Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

php - gearman gives me GEARMAN_COULD_NOT_CONNECT, it is definitely running

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...