Skip to content

Instantly share code, notes, and snippets.

@astroanu
Created October 16, 2014 10:36
Show Gist options
  • Save astroanu/e91ba7bafcd254f3049b to your computer and use it in GitHub Desktop.
Save astroanu/e91ba7bafcd254f3049b to your computer and use it in GitHub Desktop.
Gearman server get status
public static function getStatus(){
$status = null;
$handle = fsockopen(gearman_server, gearman_port,$errorNumber,$errorString,30);
if($handle!=null){
fwrite($handle,"status\n");
while (!feof($handle)) {
$line = fgets($handle, 4096);
if( $line==".\n"){
break;
}
if( preg_match("~^(.*)[ \t](\d+)[ \t](\d+)[ \t](\d+)~",$line,$matches) ){
$function = $matches[1];
$status['operations'][$function] = array(
'function' => $function,
'total' => $matches[2],
'running' => $matches[3],
'connectedWorkers' => $matches[4],
);
}
}
fwrite($handle,"workers\n");
while (!feof($handle)) {
$line = fgets($handle, 4096);
if( $line==".\n"){
break;
}
// FD IP-ADDRESS CLIENT-ID : FUNCTION
if( preg_match("~^(\d+)[ \t](.*?)[ \t](.*?) : ?(.*)~",$line,$matches) ){
$fd = $matches[1];
$status['connections'][$fd] = array(
'fd' => $fd,
'ip' => $matches[2],
'id' => $matches[3],
'function' => $matches[4],
);
}
}
fclose($handle);
}
return $status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment