8

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

Darren Beale
  • 753
  • 1
  • 9
  • 24
  • I also tried the really old packages and eventually ended up removing them, building GM 1.1.5 by hand and then building the PECL extension. – Eno Feb 15 '13 at 18:16

4 Answers4

15

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.

Eno
  • 10,730
  • 18
  • 53
  • 86
  • 1
    BTW, I opened a bug for the incorrect documentation on the PHP site. – Eno Feb 15 '13 at 18:14
  • 3
    Bingo! I had to explicitly call addServer("localhost",4730); Ta muchly. – Darren Beale Feb 17 '13 at 15:06
  • 2
    +1000 After hours of frustration, this is the simple fix that made it all work for me (Client, server and workers local on a macbook) – Asciiom Feb 18 '13 at 16:26
  • 1
    The "getting started" section is also outdated (probably). One needs to specify ports explicitly to gearman command line tool as well. See : http://stackoverflow.com/questions/16281714/unable-to-run-gearman-command-line-tool-with-gearman-1-1-6/16295236#16295236 – Andrey Rubshtein Apr 30 '13 at 10:53
  • On Debian, took a reboot after install, and had to explicitly add server and port (as above), AND which must be identical specified on both worker and client. – davmor Oct 30 '14 at 03:06
  • Just wondering if you could have avoided the reboot my (re?)starting services manually ? – Eno Aug 05 '15 at 20:45
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.

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

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();
Nätu
  • 304
  • 5
  • 16
0

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

bisw
  • 827
  • 9
  • 13