gearman gives me GEARMAN_COULD_NOT_CONNECT, it is definitely running

戏子无情 提交于 2019-11-27 06:12:57

问题


My dev server is Debian Squeeze and I'm running Gearman 1.1.5 which I compiled from source along with the php pecl extension v1.1.1

If I run the reverse_client.php script I get the GEARMAN_COULD_NOT_CONNECT error.

PHP Warning: GearmanClient::do(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:430 in /home/bealers/build/gearman-1.1.1/examples/reverse_client.php on line 26

There are a few similar posts on here about this and they all point to GM not running.

It is definitely running.

I'm starting it with these params:

PARAMS="--queue-type=MySQL --mysql-db=test_db --mysql-user=gearman --mysql-password=gearman"

If I drop the gearman_queue table in test_db then restart the daemon the table is recreated, so its mysql connection is fine and it's clearly starting.

I can also telnet to 4730 on localhost, so there's no firewall issue.

Initially GM had problems starting because it was starting before mysql, so I edited the init script

### BEGIN INIT INFO
# Provides:          gearman-job-server
# Required-Start:    $network $remote_fs $syslog mysql

and an update-rd.c gearman-job-server defaults sets it to start after and it starts fine on boot up now.

The only other thing I can think of is that initially I'd installed via apt but the version was to old so I removed it and compiled from source. /usr/sbin/gearmand no longer exists the only version is /usr/local/sbin/gearmand

ps ax | grep gearman shows only one process running.

Netstat shows only one process running`

tcp 0 0 *:4730 *:* LISTEN 2325/gearmand

The PECL lib seems fine:

php -i | grep gearman

/etc/php5/cli/conf.d/gearman.ini,
gearman
gearman support => enabled
libgearman version => 1.1.5

I'm out of ideas


回答1:


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.




回答2:


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.




回答3:


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();



回答4:


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



来源:https://stackoverflow.com/questions/14883681/gearman-gives-me-gearman-could-not-connect-it-is-definitely-running

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