public bool GearmanJob::sendStatus ( int $numerator , int $denominator )
Sends status information to the job
server and any listening clients. Use
this to specify what percentage of the
job has been completed.
To be able to use it, you will probably also have alter the client a bit to handle the communication.
Example
client.php
<?php
global $argc,$argv;
if (!file_exists($argv[1])) {
echo "File not found\n";
exit(1);
}
$gmclient= new GearmanClient();
$gmclient->addServer();
do
{
$result = $gmclient->do("linecount", file_get_contents($argv[1]));
# Check for various return packets and errors.
switch($gmclient->returnCode())
{
case GEARMAN_WORK_STATUS:
list($numerator, $denominator)= $gmclient->doStatus();
echo "Status: " . sprintf("%d%%",($numerator/$denominator)*100)
. " complete\r";
break;
case GEARMAN_SUCCESS:
break;
}
}
while($gmclient->returnCode() != GEARMAN_SUCCESS);
echo "\nResult: $result\n";
worker.php
<?php
$worker= new GearmanWorker();
$worker->addServer();
$worker->addFunction("linecount", "linecount");
while ($worker->work());
function linecount($job)
{
$lines = preg_split('/[\r\n]/',
$job->workload(),null,PREG_SPLIT_NO_EMPTY);
$linecount = count($lines);
$n = 0;
foreach ($lines as $line) {
usleep(3000);
$n++;
$job->sendStatus($n,$linecount);
$ret++;
}
return $ret;
}