
Gearman and PHP 5.4 (5.6): problems and solutions
In his previous publication, the author tried to convey to the audience interesting possibilities that the Gearman queue server opens to the PHP developer.
The publication indicated the Gearman installation algorithm and extensions for PHP. It was about PHP 5.3. On Debian7 and PHP 5.4, this algorithm does not work, without giving any errors either during installation or when running PHP scripts, however web applications using Gearman do not work.
On PHP 5.4, the situation looks like this: everything is installed, everything is fine, everything starts, no errors. However, workers do not add their tasks to the server, while
returns true.
Gap template.
The obvious solution is to try installing the latest version of pecl gearman.
But it is not installed, as in the php5.3 situation, the libgearman library version no lower than 1. * is required and that’s it.
What is the root of the problem?
When installing the gearman-job-server queue server, the same libgearman library is also installed on the system.
But as it turned out, in the Debian repositories the version of gearman-job-server (and the libgearman version) is deprecated relative to the PECL repository, and trying to install the latest version of pecl gearman gives the results described above.
How to solve a problem?
Solution 1. Build the latest Gearman from source
Solution 2. Install a slightly earlier version of pecl gearman
By trial and error for solution 2, we found the following algorithm for installing Gearman queue server and extensions for PHP 5.4
All OK. But there is an important nuance:
in the version for php5.3 this is
or
works fine.
In the php5.4 version, similar constructs in the code give an Exception.
Such a design works
Having overcome the above installation difficulties and nuances of use, we get the result:

In conclusion. Why all these dances with a tambourine in the truest sense of the word? Is Gearman really needed? I will answer yes to this question, the main thing is that working with the queue server changes the logic of PHP itself, simplifying many operations. The author announces the publication “Working with the Gearman Queue Server”, which will discuss application building techniques, logic, and a web application for monitoring and control.
UPD (03/02/2016): the method described above is fully operational in PHP 5.6 (Debian 8)
The publication indicated the Gearman installation algorithm and extensions for PHP. It was about PHP 5.3. On Debian7 and PHP 5.4, this algorithm does not work, without giving any errors either during installation or when running PHP scripts, however web applications using Gearman do not work.
On PHP 5.4, the situation looks like this: everything is installed, everything is fine, everything starts, no errors. However, workers do not add their tasks to the server, while
$worker->addFunction();
returns true.
The obvious solution is to try installing the latest version of pecl gearman.
But it is not installed, as in the php5.3 situation, the libgearman library version no lower than 1. * is required and that’s it.
What is the root of the problem?
When installing the gearman-job-server queue server, the same libgearman library is also installed on the system.
But as it turned out, in the Debian repositories the version of gearman-job-server (and the libgearman version) is deprecated relative to the PECL repository, and trying to install the latest version of pecl gearman gives the results described above.
How to solve a problem?
Solution 1. Build the latest Gearman from source
Solution 2. Install a slightly earlier version of pecl gearman
By trial and error for solution 2, we found the following algorithm for installing Gearman queue server and extensions for PHP 5.4
aptitude install gearman-job-server
aptitude install php-pear
aptitude install make
aptitude install libgearman-dev
pecl install gearman-1.0.3
echo 'extension=gearman.so' > /etc/php5/apache2/conf.d/gearman.ini
echo 'extension=gearman.so' >/etc/php5/cli/conf.d/gearman.ini
All OK. But there is an important nuance:
in the version for php5.3 this is
$worker->addServer();
or
$worker->addServer('localhost');
works fine.
In the php5.4 version, similar constructs in the code give an Exception.
Such a design works
$worker->addServer('127.0.0.1', 4730);
Having overcome the above installation difficulties and nuances of use, we get the result:

In conclusion. Why all these dances with a tambourine in the truest sense of the word? Is Gearman really needed? I will answer yes to this question, the main thing is that working with the queue server changes the logic of PHP itself, simplifying many operations. The author announces the publication “Working with the Gearman Queue Server”, which will discuss application building techniques, logic, and a web application for monitoring and control.
UPD (03/02/2016): the method described above is fully operational in PHP 5.6 (Debian 8)