1. introduction Gearman installation is divided into two steps. Step 2 is the installation of gearmand, and step 2 is the installation of PHP extension of gearman. Step 2: install gearmand 1. first install libdrizzle # yuminstalllibdrizzlelibdrizzle-devel2. install gearman (two methods 1. yum2. source
I. INTRODUCTION
Gearman is installed in two steps. Step 2 is gearmand installation, and step 2 is the PHP extension installation of gearman.
Step 2:
2. installation of gearmand
1. first install libdrizzle
# Yum install libdrizzle-devel
2. install gearman (two methods: 1. yum2. source package ). (C server)
1) yum installation
# Rpm-ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/epel-release-6-5.noarch.rpm
# Yum install-y gearmand
2) install the source code package
# Cd/opt/build/
# Wget https://launchpad.net/gearmand/trunk/0.34/+download/gearmand-0.34.tar.gz
# Tar zxf gearmand-0.34.tar.gz
# Cd gearmand-0.34
#./Configure
# Make & make install
3. start the gearman service
1) yum installation method
#/Etc/init. d/gearmand start
2) source code package installation method
#/Opt/building/gearmand-0.34/sbin/gearmand-d
# Gearmand-vvv-u root
INFO Starting up
INFO Listening on ::: 4730 (6)
INFO Creating wakeup pipe
INFO Creating IO thread wakeup pipe
INFO Adding event for listening socket (6)
INFO Adding event for wakeup pipe
INFO Entering main event loop
III. PHP extension installation of gearman
1. download extended: http://pecl.php.net/package/gearman
Wget http://pecl.php.net/get/gearman-1.1.2.tgz
Tar zxvf gearman-1 ....
Cd gearman-1...
Phpize
./Configure
Make & make install
Soon after the installation is completed, the path of the so file will be displayed, for example:/usr/lib64/php/modules/
2. in php. add extension = "/usr/lib64/php/modules/gearman at the end of ini. so ", restart apache, and output php-info | grep" gearman ", php-m, or phpinfo () on the webpage.
FAQ: If you are prompted that php-config cannot be found during configure, specify. For example,-with-php-config =/usr/local/php/bin/php-config. Be sure to specify the complete directory instead of writing the directory only.
4. start and test gearman
1. gearmand-p 4730-L 121.111.111.111 -- log-file =/tmp/gearmand-4730.log -- pid-file =/tmp/gearmand-4730.pid-d
2. Client:
$ MyParams = array ();
$ MyParams ['level'] = "warn ";
$ MyParams ['content'] = "it's a test ";
$ Client = new GearmanClient ();
// If gearman does not respond within 300 milliseconds, close the connection directly.
$ Client-> setTimeout (300 );
$ Client-> addServer ("121.111.111.111", "4730 ");
$ Client-> doBackground ("log", json_encode ($ myParams ));
3. Server
$ Worker = new GearmanWorker ();
$ Worker-> addServer ("112.111.111.111", "4730 ");
$ Worker-> addFunction ("log", "doLog ");
While ($ worker-> work ());
Function doLog ($ job ){
Global $ logger, $ logLevels, $ myParams;
$ MyParams = NULL;
$ MyParams = json_decode ($ job-> workload ());
$ Level = $ myParams-> level;
If (! In_array ($ level, $ logLevels) $ level = 'info ';
$ Logger-> $ level ($ myParams-> content );
}
Refer:
Http://www.cppblog.com/guojingjia2006/archive/2013/01/07/197076.html
Http://www.xiaomlove.com/phpinstall gearmanextended real-time asynchronous task/