<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Get the status of a background job</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="gearmanclient.geterrno.html">GearmanClient::getErrno</a></div> <div class="next" style="text-align: right; float: right;"><a href="gearmanclient.ping.html">GearmanClient::ping</a></div> <div class="up"><a href="class.gearmanclient.html">GearmanClient</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="gearmanclient.jobstatus" class="refentry"> <div class="refnamediv"> <h1 class="refname">GearmanClient::jobStatus</h1> <h1 class="refname">gearman_job_status</h1> <p class="verinfo">(PECL gearman >= 0.5.0)</p><p class="refpurpose"><span class="refname">GearmanClient::jobStatus</span> -- <span class="refname">gearman_job_status</span> — <span class="dc-title">Get the status of a background job</span></p> </div> <div class="refsect1 description" id="refsect1-gearmanclient.jobstatus-description"> <h3 class="title">Description</h3> <p class="para">Object oriented style (method):</p> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><strong>GearmanClient::jobStatus</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$job_handle</code></span> )</div> <p class="para rdfs-comment"> 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. </p> </div> <div class="refsect1 parameters" id="refsect1-gearmanclient.jobstatus-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">job_handle</code></em></span> <dd> <p class="para"> The job handle assigned by the Gearman server </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-gearmanclient.jobstatus-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> 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. </p> </div> <div class="refsect1 examples" id="refsect1-gearmanclient.jobstatus-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4327"> <p><strong>Example #1 Monitor the status of a long running background job</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">/* create our object */<br /></span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">= new </span><span style="color: #0000BB">GearmanClient</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* add the default server */<br /></span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-></span><span style="color: #0000BB">addServer</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* run reverse client */<br /></span><span style="color: #0000BB">$job_handle </span><span style="color: #007700">= </span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-></span><span style="color: #0000BB">doBackground</span><span style="color: #007700">(</span><span style="color: #DD0000">"reverse"</span><span style="color: #007700">, </span><span style="color: #DD0000">"this is a test"</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-></span><span style="color: #0000BB">returnCode</span><span style="color: #007700">() != </span><span style="color: #0000BB">GEARMAN_SUCCESS</span><span style="color: #007700">)<br />{<br /> echo </span><span style="color: #DD0000">"bad return code\n"</span><span style="color: #007700">;<br /> exit;<br />}<br /><br /></span><span style="color: #0000BB">$done </span><span style="color: #007700">= </span><span style="color: #0000BB">false</span><span style="color: #007700">;<br />do<br />{<br /> </span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$stat </span><span style="color: #007700">= </span><span style="color: #0000BB">$gmclient</span><span style="color: #007700">-></span><span style="color: #0000BB">jobStatus</span><span style="color: #007700">(</span><span style="color: #0000BB">$job_handle</span><span style="color: #007700">);<br /> if (!</span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]) </span><span style="color: #FF8000">// the job is known so it is not done<br /> </span><span style="color: #0000BB">$done </span><span style="color: #007700">= </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /> echo </span><span style="color: #DD0000">"Running: " </span><span style="color: #007700">. (</span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">] ? </span><span style="color: #DD0000">"true" </span><span style="color: #007700">: </span><span style="color: #DD0000">"false"</span><span style="color: #007700">) . </span><span style="color: #DD0000">", numerator: " </span><span style="color: #007700">. </span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">] . </span><span style="color: #DD0000">", denomintor: " </span><span style="color: #007700">. </span><span style="color: #0000BB">$stat</span><span style="color: #007700">[</span><span style="color: #0000BB">3</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br />while(!</span><span style="color: #0000BB">$done</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"done!\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> 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! </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-gearmanclient.jobstatus-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="gearmanclient.dostatus.html" class="methodname" rel="rdfs-seeAlso">GearmanClient::doStatus()</a> - Get the status for the running task</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="gearmanclient.geterrno.html">GearmanClient::getErrno</a></div> <div class="next" style="text-align: right; float: right;"><a href="gearmanclient.ping.html">GearmanClient::ping</a></div> <div class="up"><a href="class.gearmanclient.html">GearmanClient</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>