Created
May 12, 2011 21:21
-
-
Save zircote/969477 to your computer and use it in GitHub Desktop.
Redis status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/** | |
* | |
* Result string for parsing | |
* @var string | |
*/ | |
$string = null; | |
/** | |
* | |
* replace hostname with target meteor server | |
* @var string | |
*/ | |
$host = "tcp://localhost:6379"; | |
/** | |
* | |
* result container | |
* @var array | |
*/ | |
$result = array(); | |
/** | |
* | |
* socket resource | |
* @var int | |
*/ | |
$fp = fsockopen($host); | |
if (! $fp) { | |
die('error failed to connect'); | |
} | |
fwrite($fp, "info\r\n"); | |
while (true) { | |
$string .= $out = fgets($fp, 512); | |
if (strlen($out) < 3) { | |
break; | |
} | |
} | |
fclose($fp); | |
$lines = explode("\n", $string); | |
foreach ($lines as $value) { | |
if (strlen($value) && strstr($value,':')) { | |
$parts = split(':', $value); | |
$result[$parts[0]] = trim($parts[1]); | |
} | |
} | |
echo json_encode($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment