Created
May 12, 2011 21:23
-
-
Save zircote/969484 to your computer and use it in GitHub Desktop.
Meteor 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://meteor.example.com:4671"; | |
$fp = fsockopen($host); | |
if (! $fp) { | |
die('error failed to connect'); | |
} | |
fwrite($fp, "SHOWSTATS\r\n"); | |
while (! feof($fp)) { | |
$string .= fgets($fp, 512); | |
if (strstr($string, '--EOT--')) { | |
fwrite($fp, "QUIT\r\n"); | |
} | |
} | |
fclose($fp); | |
$string = str_replace(array("OK\r\n", "--EOT--\r\n"), '', $string); | |
$lines = explode("\r\n", $string); | |
foreach ($lines as $value) { | |
if (strlen($value)) { | |
$parts = split(': ', $value); | |
$result[$parts[0]] = trim($parts[1]); | |
} | |
} | |
$result = json_encode($result); | |
print_r($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment