Enterprise Integration Zone is brought to you in partnership with:

Lorna Jane Mitchell is a PHP developer, blogger, trainer and evangelist from Leeds in the UK. She is active with phpwomen.org and her local user group PHP North West, and writes for a variety of outlets, including her own blog at lornajane.net. She is an active member of the PHP and open source communities and contributes to the joind.in event feedback project. When she's not at her computer, Lorna enjoys yarn craft, hobby electronics, and her home renovation project. Lorna is a DZone MVB and is not an employee of DZone and has posted 81 posts at DZone. You can read more from them at their website. View Full User Profile

PHP and Gearman: Unable to Connect after Upgrade

03.01.2013
| 2587 views |
  • submit to reddit

I upgraded PHP and related pecl modules on my development machine today, and ran into a problem with Gearman. Actually I ran into more than one! Firstly the challenge of getting the newest pecl version working with a gearman version. Then an error where my existing PHP application couldn't connect to gearman after upgrade.

Installing Gearmand and Pecl Gearman on Ubuntu 12.10

First up: the version of gearman in aptitude isn't new enough to match the (lovely, shiny) new version in pecl. This problem will solve itself with future releases and is just the result of the different speeds that releases get to users via different channels. To get this all set up, I used the excellent tutorial I found here: http://www.phamviet.net/2012/10/10/ubuntu-php-5-4-x-and-gearman-troubleshooting.

After working through this tutorial, I was able to install the pecl gearman extension at the newest version (1.1.1) successfully.

Dealing with "Unable to connect" error

The code I was trying to run is pretty hardened, it's been in production for nearly two years - yet it just did not work after upgrade and the error "unable to connect" made it sound more like a gearman problem than a PHP one, so I didn't spot the issue straight away. The exact error from my logs:

PHP Warning: GearmanClient::doBackground(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:430

In fact, what happened was that the GearmanClient::addServers() method now requires that the port also be specified with an IP address, in the format 127.0.0.1:4730 whereas previously it would take an IP address and assume the default port number. I simply changed my previous code:

$client->addServers('127.0.0.1'); 

To the updated version like this:

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

And all was well. It's a tricky thing to track down so I hope this helps if it happened to you! I also went back and edited the previous code samples on this blog in attempt to have other people avoid the issue.

Published at DZone with permission of Lorna Mitchell, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)