In his
previous publication, the author tried to convey to the audience interesting opportunities that the Gearman queue server opens for 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
$worker->addFunction();
returns true.
Pattern break.The obvious solution is to try installing the latest version of pecl gearman.
But it is not installed, as in the situation of php5.3, libgearman library of version not less than 1 is required. * And that's it.
What is the root of the problem?
When you install the queue server gearman-job-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 version of libgearman) is outdated relative to the PECL repository, and an attempt to install the latest version of pecl gearman gives the results described above.
How to solve a problem?
Solution 1. Build the latest version of Gearman
from source.Solution 2: Install a slightly earlier version of pecl gearman
By trial and error method for solution 2, this algorithm was found for installing the 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 here it is
$worker->addServer();
or
$worker->addServer('localhost');
works fine.
In the php5.4 version, similar constructs in the code give Exception.
This construction works
$worker->addServer('127.0.0.1', 4730);
Having overcome the above installation difficulties and nuances of use, we get the result:

')
Finally. Why all these dances with a tambourine in the truest sense of the word? Is Gearman so necessary? I will answer “yes” to this question, the main thing - 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 examine the techniques for building applications, logic, and a web application for monitoring and management.UPD (03/02/2016): The method described above is fully functional in PHP 5.6 (Debian 8)