Skip to content

Instantly share code, notes, and snippets.

@zircote
Created May 12, 2011 21:23
Show Gist options
  • Save zircote/969484 to your computer and use it in GitHub Desktop.
Save zircote/969484 to your computer and use it in GitHub Desktop.
Meteor Status
#!/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