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:
Alan Collison 2009-10-30 14:57:58 +00:00
parent 316087ba95
commit 011ce33ac2

View file

@ -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>