3

I installed gearmand 1.1.5 on my server, and tried the examples provided with the installation after starting the server. They work pretty correctly (the echo example works, the reverse doesn't work as expected, but doesn't gives any error).

Then I installed the php wrapper using pecl. The version is the last stable (1.1.1). Obviously I added the extension to php.ini, and my php --info|grep gearman output is:

gearman
gearman support => enabled
libgearman version => 1.1.5
PWD => /root/gearman-1.1.1/examples
OLDPWD => /root/gearman-1.1.1
_SERVER["PWD"] => /root/gearman-1.1.1/examples
_SERVER["OLDPWD"] => /root/gearman-1.1.1

Then I tried the echo example in the pecl package, the worker starts correctly:

[~/gearman-1.1.1/examples]# php reverse_worker.php 
Starting
Waiting for job...

the client, instead, gives me the following error:

[~/gearman-1.1.1/examples]# php reverse_client.php 
Starting
Sending job
PHP Warning:  GearmanClient::do(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:430 in /root/gearman-1.1.1/examples/reverse_client.php on line 26
PHP Stack trace:
PHP   1. {main}() /root/gearman-1.1.1/examples/reverse_client.php:0
PHP   2. GearmanClient->do() /root/gearman-1.1.1/examples/reverse_client.php:26

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

Call Stack:
    0.0001     228408   1. {main}() /root/gearman-1.1.1/examples/reverse_client.php:0
    0.0003     229552   2. GearmanClient->do() /root/gearman-1.1.1/examples/reverse_client.php:26

RET: 26

In the gearman daemon's log there is no sign of activity for this php tests, while it logged all previous examples I tried.

How can I fix this error? Thanks.

Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63
  • nice blog about gearman .. `http://www.brijneet.com/2011/gearman/` – Suhel Meman Feb 07 '13 at 11:11
  • Can you provide the code you used to connect? I did find adding 127.0.0.1 for localhost fixed issues – Simon Bennett Feb 10 '13 at 15:23
  • We killed and restarted the daemon and now it's working. Maybe it was a port binding/host resolution problem? We made a lot of tests, and probably something screwed up. I also added a line in /etc/hosts (127.0.0.1 localhost). Thanks for the advices – Lorenzo Marcon Feb 11 '13 at 09:51
  • 3
    Possible duplicate of [gearman gives me GEARMAN\_COULD\_NOT\_CONNECT, it is definitely running](https://stackoverflow.com/questions/14883681/gearman-gives-me-gearman-could-not-connect-it-is-definitely-running) – LW001 Nov 16 '17 at 14:49

2 Answers2

4

Your should always use addServer("127.0.0.1", 4730), not addServer(), despite what php documentation says.

0

In case if you have used something like this

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

or

$client->addServers();

and still it didnt work then 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.

Jatin Dhoot
  • 4,294
  • 9
  • 39
  • 59