After running a simple PHP Gearman client script, it throws the error below:
Solution:
The default host and port of Gearman is “localhost” and 4730 respectively. Normally you don’t need to mention it explicitly according to the documentation. But apart from the documentation, I had to explicitly mention it in both client and worker script to make it work.
$worker->addServer(“localhost”,4730);
Ref: You might also want to look into this post.
Sample Worker script: (/usr/bin/php ./gearman_worker.php)
addServer(“localhost”,4730);
// Register the processing function
$worker->addFunction(“process_string”, “processString”);
// Trigger the infinite loop
while ($worker->work());
/*
print “Waiting for job…\n”;
while($gmworker->work())
{
if ($gmworker->returnCode() != GEARMAN_SUCCESS)
{
echo “return_code: ” . $gmworker->returnCode() . “\n”;
break;
}
}
*/
// The main function that processes the job
function processString($job)
{
// get the workload – it’s a string. use serialization to pass objects
$param = $job->workload();
return “You passed the string: {$param} \n It had: “.strlen($param).” chars \n”;
}
?>
Sample Client script: (/usr/bin/php ./gearman_client.php)
addServer(“localhost”,4730);
// print the output of the job. first parameter is the job name, second one is the parameter
print $client->do(“process_string”, “Hello Gearman from Client!”);/*
# set some arbitrary application data
$data[‘foo’] = ‘bar’;# add two tasks
$task= $gmc->addTask(“reverse”, “foo”, $data);
$task2= $gmc->addTaskLow(“reverse”, “bar”, NULL);# run the tasks in parallel (assuming multiple workers)
if (! $gmc->runTasks())
{
echo “ERROR ” . $gmc->error() . “\n”;
exit;
}echo “DONE\n”;
*/
?>
I’ll add a more complete example script later.
Hope, it’ll help someone!
July 16th, 2017 at 8:40 pm
Do you mind iff I quote a few of your articles as long as I
provide credit and sources back to your blog?
My blog site is inn tthe very same area of interest as yours aand my users
would deefinitely benefit from some off thhe information you present
here. Please llet me know iff this alright with you.
Appreciate it!
January 9th, 2018 at 7:09 am
http://cicimusic.com/images/online-mp3.png песня дай мне собраться с мыслями не могу слушать брати мне псих читаяит скачать минус кукушка скачать песню гвардия скачать песню сердце мое душу греет я милый парень песня серебро моя любовь скачати пісню двіж muzonx ru nor tarva erg sublab feel this way cлушать http://www.cicimusic.com/
January 28th, 2019 at 4:11 pm
Вчера вечером разглядывал содержание сети, и вдруг к своему восторгу увидел хороший ресурс.
Я про него:
Салон красоты
Мне этот веб-сайт показался очень хорошим . Всего наилучшего !