gearman gives me GEARMAN_COULD_NOT_CONNECT, it is definitely running

Deadly 提交于 2019-11-29 06:49:44

I had the same problem and recently solved them after a couple days of frustration (hard to troubleshoot since there are three processes to worry about :-)

It appears (at least in my case) that the PHP documentation for GearmanClient::addServer() and GearmanWorker::addServer() is incorrect. Specifically, the docs seem to imply that hostname and port number are optional and that it will use localhost and port 4730 as defaults if you do not specify them. This never works - it suddenly occurred to me today to try explicitly specifying them for both client and worker processes and everything started working.

Try specifying all values for hostnames and ports and see if this works for you.

In case if you have used something like this

$client->addServers('127.0.0.1', 4730);

or

$client->addServers();

use something like this

$client->addServers('127.0.0.1:4730');

PS - I have used localhost IP, this can be replaced with actual host IP.

In my case it's little different. I got this same error when I had my addServer code inside the loop.

$client = new GearmanClient();
for ($i=0; $i<100000; $i++) {
  $client->addServer("127.0.0.1", 4730);
  $data = json_encode(array('job_id' => $i, 'task_name' => 'send-email'));
  $client->addTaskBackground('sendEmail', $data);
}
$client->runTasks();

And this fixed it for me:

$client = new GearmanClient();
$client->addServer("127.0.0.1", 4730);
for ($i=0; $i<100000; $i++) {
  $data = json_encode(array('job_id' => $i, 'task_name' => 'send-email'));
  $client->addTaskBackground('sendEmail', $data);
}
$client->runTasks();

May be this could help someone. If you want to use single server, you can use

$client->addServer($host, $port)
e.g. $client->addServer('127.0.0.1', 4730)

http://php.net/manual/en/gearmanclient.addserver.php

If you want to use multiple server, then you can use

$client->addServers($host1:$port1, $host2:$port2, $host3:$port3)
e.g. $client->addServers('127.0.0.1:4730', '127.0.0.2:8080')

http://php.net/manual/en/gearmanclient.addservers.php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!