Closed tboloo closed 9 years ago
Sorry this is so delayed; this is a result of the C++ library deviating a bit from the existing standard without documenting it -- the PHP client wraps the C++ library and so I will need to support a few other message types:
SUBMIT_REDUCE_JOB,
SUBMIT_REDUCE_JOB_BACKGROUND,
GRAB_JOB_ALL,
JOB_ASSIGN_ALL,
GET_STATUS_UNIQUE,
STATUS_RES_UNIQUE;
Cool, when do expect to publish the updated jar?
It looks like just responding to GRAB_JOB_ALL
with a standard JOB_ASSIGN_*
message makes the PHP worker happy. You can build master yourself or I can publish a JAR for you somewhere if that helps you test it.
My worker looks like this:
<?php
echo "Starting\n";
# Create our worker object.
$gmworker= new GearmanWorker();
# Add default server (localhost).
$gmworker->addServer();
# Register function "reverse" with the server. Change the worker function to
# "reverse_fn_fast" for a faster worker with no output.
$gmworker->addFunction("reverse", "reverse_fn");
print "Waiting for job...\n";
while($gmworker->work())
{
if ($gmworker->returnCode() != GEARMAN_SUCCESS)
{
echo "return_code: " . $gmworker->returnCode() . "\n";
break;
}
}
function reverse_fn($job)
{
echo "Received job: " . $job->handle() . "\n";
$workload = $job->workload();
$workload_size = $job->workloadSize();
echo "Workload: $workload ($workload_size)\n";
# This status loop is not needed, just showing how it works
for ($x= 0; $x < $workload_size; $x++)
{
echo "Sending status: " . ($x + 1) . "/$workload_size complete\n";
$job->sendStatus($x+1, $workload_size);
$job->sendData(substr($workload, $x, 1));
sleep(1);
}
$result= strrev($workload);
echo "Result: $result\n";
# Return what we want to send back to the client.
return $result;
}
# A much simpler and less verbose version of the above function would be:
function reverse_fn_fast($job)
{
return strrev($job->workload());
}
?>
I would be great if you could help me, and publish the JAR.
Works like a charm, thanks. BTW, I have created Docker environment for easier and environment-independent testing, perhaps you find it useful.
Setup:
Sample worker (taken from here ) When trying to run the worker (more precisely when
$gmworker->work()
is called) server fails with NullPointerException, which seems to cause the infinite loop, with information as below:BTW client and worker work as expected on gearmand