Skip to content

Instantly share code, notes, and snippets.

@pcdinh
Created May 17, 2010 11:25
Show Gist options
  • Select an option

  • Save pcdinh/403660 to your computer and use it in GitHub Desktop.

Select an option

Save pcdinh/403660 to your computer and use it in GitHub Desktop.
#!/usr/local/php5-fcgi/bin/php
<?php
$client = new GearmanClient();
$client->addServer('127.0.0.1');
echo "Sending 1000 job\n";
do
{
$start = microtime(true);
for ($i = 0; $i < 1000; $i++)
{
$result = $client->doBackground("reverse", "Hello!");
}
echo "Elapsed time: ".(microtime(true) - $start)."\n";
// Check for various return packets and errors.
switch ($client->returnCode())
{
case GEARMAN_WORK_DATA:
echo "Data: $result\n";
break;
case GEARMAN_WORK_STATUS:
list($numerator, $denominator) = $client->doStatus();
echo "Status: $numerator/$denominator complete\n";
break;
case GEARMAN_WORK_FAIL:
echo "Failed\n";
exit;
case GEARMAN_SUCCESS:
break;
default:
echo "RET: " . $client->returnCode() . "\n";
exit;
}
} while ($client->returnCode() != GEARMAN_SUCCESS);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment