mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
corrected return value; added note that can issue E_WARNING; added example code
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@290077 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
316087ba95
commit
011ce33ac2
1 changed files with 63 additions and 2 deletions
|
@ -15,7 +15,8 @@
|
|||
</methodsynopsis>
|
||||
<para>
|
||||
Causes the worker to wait for activity from one of the Gearman job servers when operating
|
||||
in non-blocking I/O mode.
|
||||
in non-blocking I/O mode. On failure, issues a <constant>E_WARNING</constant> with the last Gearman error
|
||||
encountered.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
|
@ -27,7 +28,67 @@
|
|||
<refsect1 role="returnvalues">
|
||||
&reftitle.returnvalues;
|
||||
<para>
|
||||
A standard Gearman return value.
|
||||
&return.success;
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<para>
|
||||
<example>
|
||||
<title>Running worker in non-blocking mode</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
echo "Starting\n";
|
||||
|
||||
# Create our worker object
|
||||
$worker= new GearmanWorker();
|
||||
|
||||
# Make the worker non-blocking
|
||||
$worker->addOptions(GEARMAN_WORKER_NON_BLOCKING);
|
||||
|
||||
# Add the default server (localhost, port 4730)
|
||||
$worker->addServer();
|
||||
|
||||
# Add our reverse function
|
||||
$worker->addFunction('reverse', 'reverse_fn');
|
||||
|
||||
# Try to grab a job
|
||||
while (@$worker->work() ||
|
||||
$worker->returnCode() == GEARMAN_IO_WAIT ||
|
||||
$worker->returnCode() == GEARMAN_NO_JOBS)
|
||||
{
|
||||
if ($worker->returnCode() == GEARMAN_SUCCESS)
|
||||
continue;
|
||||
|
||||
echo "Waiting for next job...\n";
|
||||
if (!@$worker->wait())
|
||||
{
|
||||
if ($worker->returnCode() == GEARMAN_NO_ACTIVE_FDS)
|
||||
{
|
||||
# We are not connected to any servers, so wait a bit before
|
||||
# trying to reconnect.
|
||||
sleep(5);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
echo "Worker Error: " . $worker->error() . "\n";
|
||||
|
||||
function reverse_fn($job)
|
||||
{
|
||||
return strrev($job->workload());
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
|
|
Loading…
Reference in a new issue