略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: GearmanClient::jobStatus

2024-11-13

GearmanClient::jobStatus

gearman_job_status

(PECL gearman >= 0.5.0)

GearmanClient::jobStatus -- gearman_job_statusGet the status of a background job

说明

面向对象风格 (method):

public GearmanClient::jobStatus(string $job_handle): array

Gets the status for a background job given a job handle. The status information will specify whether the job is known, whether the job is currently running, and the percentage completion.

参数

job_handle

由 Gearman 服务器指派的工作句柄。

返回值

An array containing status information for the job corresponding to the supplied job handle. The first array element is a boolean indicating whether the job is even known, the second is a boolean indicating whether the job is still running, and the third and fourth elements correspond to the numerator and denominator of the fractional completion percentage, respectively.

范例

示例 #1 Monitor the status of a long running background job

<?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!

参见

add a noteadd a note

User Contributed Notes 2 notes

up
13
bot at boxconnect dot org
6 years ago
The example above reads:
if (!$stat[0]) // the job is known so it is not done

I think the comment is wrong, it should read "the job is unknown, so it is done".
Regards,
Jan
up
-2
richard@anon
5 years ago
@Jan

if (!$stat[0]) // the job is known so it is not done

I believe to be correct. I read it as, if $stat[0] returns anything but false, the job is currently running, so we are not done. However, if we cannot find $stat[0] (ie: the job handle no longer exists) then the job is done.

--Richard

官方地址:https://www.php.net/manual/en/gearmanclient.jobstatus.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3