GearmanClient::jobStatus
GearmanClient::jobStatus
gearman_job_status
(PECL gearman >= 0.5.0)
GearmanClient :: jobStatus - gearman_job_status - 获取后台作业的状态
描述
面向对象的风格(方法):
public array GearmanClient::jobStatus ( string $job_handle )
获取给定作业句柄的后台作业的状态。状态信息将指定作业是否已知,作业当前是否正在运行以及完成百分比。
参数
job_handle
由Gearman服务器分配的作业句柄
返回值
包含与提供的作业句柄对应的作业的状态信息的数组。第一个数组元素是一个布尔值,指示作业是否已知,第二个布尔值指示作业是否仍在运行,第三个和第四个元素分别对应于分数完成百分比的分子和分母。
例
示例#1监视长时间运行的后台作业的状态
<?php
/* create our object */
$gmclient= new GearmanClient(
/* add the default server */
$gmclient->addServer(
/* run reverse client */
$job_handle = $gmclient->doBackground("reverse", "this is a test"
if ($gmclient->returnCode() != GEARMAN_SUCCESS)
{
echo "bad return code\n";
exit;
}
$done = false;
do
{
sleep(3
$stat = $gmclient->jobStatus($job_handle
if (!$stat[0]) // the job is known so it is not done
$done = true;
echo "Running: " . ($stat[1] ? "true" : "false") . ", numerator: " . $stat[2] . ", denomintor: " . $stat[3] . "\n";
}
while(!$done
echo "done!\n";
?>
上面的例子会输出:
Running: true, numerator: 3, denomintor: 14
Running: true, numerator: 6, denomintor: 14
Running: true, numerator: 9, denomintor: 14
Running: true, numerator: 12, denomintor: 14
Running: false, numerator: 0, denomintor: 0
done!
扩展内容
- GearmanClient :: doStatus() - 获取正在运行的任务的状态
← GearmanClient::getErrno