Gearman gives me GEARMAN_COULD_NOT_CONNECT, it definitely works

My Dev server is Debian Squeeze, and I run Gearman 1.1.5, which I compiled from the source along with the php extension pecl v1.1.1

If I run reverse_client.php script, I get a 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 several similar messages here, and all of them indicate that GM is not working.

It definitely works.

I start with these options:

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

If I reset the gearman_queue table to test_db, restart the daemon that recreates the table, so its connection to mysql is great and it clearly starts.

I can also install telnet on 4730 on localhost, so there is no problem with the firewall.

GM initially had problems since it started before mysql, so I edited the init script

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

and update-rd.c gearman-job-server defaults sets it to start and starts working normally at boot.

The only thing I can think of is what I originally installed through apt, but the version was old, so I deleted it and compiled from the source. / usr / sbin / gearmand no longer exists, the only version is / usr / local / sbin / gearmand

ps ax | grep gearman ps ax | grep gearman shows only one running process.

Netstat shows only one process:

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

PECL lib seems wonderful:

php -i | grep gearman

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

I have no ideas

+8
php debian gearman
source share
4 answers

I had the same problem and recently solved them after several days of frustration (it’s hard to fix the problem, because there are three processes to worry about :-)

It seems (at least in my case) that the PHP documentation for GearmanClient :: addServer () and GearmanWorker :: addServer () is incorrect. In particular, the docs seem to imply that the host name and port number are optional and that it will use localhost and port 4730 as default values ​​if you do not specify them. This one never works - it suddenly occurred to me to try to explicitly specify them for both client and work processes, and it all started.

Try specifying all the values ​​for host and port names and see if this works for you.

+15
source share

If you 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 used localhost IP, this can be replaced with the actual host IP.

+2
source share

Maybe this can help someone. If you want to use one server, you can use

 $client->addServer($host, $port) eg $client->addServer('127.0.0.1', 4730) 

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

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

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

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

0
source share

In my case, this is a little different. I got the same error when I have addServer code inside a 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(); 
0
source share

All Articles