murshed ahmmad khan (usamurai) on May 1st, 2013
  • Sumo

Gearman flow chart

After running a simple PHP Gearman client script, it throws the error below:

PHP Warning: GearmanClient::do(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/ in /home/work/public_html/site/gearman_client.php on line 14


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.


Ref: You might also want to look into this post.

Sample Worker script: (/usr/bin/php ./gearman_worker.php)

// Register the processing function
$worker->addFunction(“process_string”, “processString”);
// Trigger the infinite loop
while ($worker->work());

print “Waiting for job…\n”;
if ($gmworker->returnCode() != GEARMAN_SUCCESS)
echo “return_code: ” . $gmworker->returnCode() . “\n”;

// 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)

// 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”;

echo “DONE\n”;


I’ll add a more complete example script later.

Hope, it’ll help someone!

19 Responses to “Tips: Gearman connect error “Failed to send server-options packet” in PHP”

  1. 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!

  2. песня дай мне собраться с мыслями не могу слушать брати мне псих читаяит скачать минус кукушка скачать песню гвардия скачать песню сердце мое душу греет я милый парень песня серебро моя любовь скачати пісню двіж muzonx ru nor tarva erg sublab feel this way cлушать

  3. Вчера вечером разглядывал содержание сети, и вдруг к своему восторгу увидел хороший ресурс.
    Я про него:
    Салон красоты
    Мне этот веб-сайт показался очень хорошим . Всего наилучшего !

  4. سكس محارم

  5. важный вебсайт

  6. i loved this кардинг форум

  7. A handwritten book is a book

  8. from a printed book, reproduction

  9. A handwritten book is a book

  10. books in ancient times was papyrus

  11. from lat. manus – “hand” and scribo – “I write”) ]

  12. Europe, and in Ancient Russia

  13. European glory, and even after

  14. (palimpsests). In the XIII-XV centuries in

  15. Since the era of Charlemagne

  16. from lat. manus – “hand” and scribo – “I write”) ]

  17. w augustowie

  18. new texts were rewritten


  1. Anonymous

Leave a Reply