GearmanClient::doStatus

(PECL gearman >= 0.5.0)

GearmanClient::doStatusGet the status for the running task

Description

public GearmanClient::doStatus(): array

Returns the status for the running task. This should be used between repeated GearmanClient::doNormal() calls.

Parameters

This function has no parameters.

Return Values

An array representing the percentage completion given as a fraction, with the first element the numerator and the second element the denomintor.

Examples

Example #1 Get the status of a long running job

The worker in this example has an artificial delay added during processing of the string to be reversed. After each delay it calls GearmanJob::status() which the client then picks up.

<?php

echo "Starting\n";

# Create our client object.
$gmclient= new GearmanClient();

# Add default server (localhost).
$gmclient->addServer();

echo 
"Sending job\n";

# Send reverse job
do
{
  
$result $gmclient->doNormal("reverse""Hello!");

  
# Check for various return packets and errors.
  
switch($gmclient->returnCode())
  {
    case 
GEARMAN_WORK_DATA:
      break;
    case 
GEARMAN_WORK_STATUS:
      
# get the current job status
      
list($numerator$denominator)= $gmclient->doStatus();
      echo 
"Status: $numerator/$denominator complete\n";
      break;
    case 
GEARMAN_WORK_FAIL:
      echo 
"Failed\n";
      exit;
    case 
GEARMAN_SUCCESS:
      break;
    default:
      echo 
"RET: " $gmclient->returnCode() . "\n";
      exit;
  }
}
while(
$gmclient->returnCode() != GEARMAN_SUCCESS);

echo 
"Success: $result\n";

?>

The above example will output something similar to:

Starting
Sending job
Status: 1/6 complete
Status: 2/6 complete
Status: 3/6 complete
Status: 4/6 complete
Status: 5/6 complete
Status: 6/6 complete
Success: !olleH

See Also

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial