Установка сервера Gearman - Сетевой брокер сообщений

apt-get install gearman-server gearman-client

Установка Gearman PHP extensions на Debian 6

http://gearman.org

http://download.datadifferential.com - libgearman

http://pecl.php.net/package/gearman - модуль PHP

Устанавливаем все необходимые пакеты

sudo apt-get install php5-dev libevent-dev uuid-dev
sudo apt-get install gcc build-essential g++ libboost-dev libboost-program-options-dev

Устанавливаем библиотеку libgearman и модуль для PHP

nano ./gearman.sh

ver="1.1.3" echo -e "## Install libgearman $ver ##" dpkg -r gearmand sleep 1 wget http://download.datadifferential.com/gearmand-${ver}.tar.gz tar -xvzf gearmand-${ver}.tar.gz cd ./gearmand-${ver} ./configure sleep 1 make checkinstall make clean cd .. ver1="1.1.0" echo -e "## Install php-gearman $ver1 ##" dpkg -r gearman sleep 1 wget http://pecl.php.net/get/gearman-${ver1}.tgz tar -zxvf gearman-${ver1}.tgz cd ./gearman-${ver1} phpize ./configure make checkinstall make clean cd ..

Установка скриптом

nano ./install-gearman.sh

echo -e "## Install development soft ##" aptitude install gcc build-essential g++ libboost-dev libboost-program-options-dev libboost-all-dev libevent-dev uuid-dev -y echo -e "## Uninstall Gearman Job Server & php-gearman client ##" dpkg -r gearman dpkg -r gearmand echo -e "## Install Gearman Job Server & php-gearman client ##" ver="1.1.1" echo -e "## Install libgearman $ver ##" dpkg -r gearmand sleep 1 wget http://download.datadifferential.com/gearmand-${ver}.tar.gz tar -xvzf gearmand-${ver}.tar.gz cd ./gearmand-${ver} ./configure sleep 1 make checkinstall make clean cd .. adduser gearman --home /var/www --no-create-home --disabled-login --disabled-password --ingroup www-data if ! test -d /var/log/gearman-job-server then mkdir /var/log/gearman-job-server chown gearman:www-data -R /var/log/gearman-job-server fi if ! test -d /var/run/gearman then mkdir /var/run/gearman chown gearman:www-data -R /var/run/gearman fi echo ' #!/bin/sh # Gearman server and library # Copyright (C) 2008 Brian Aker, Eric Day # All rights reserved. # # Use and distribution licensed under the BSD license. See # the COPYING file in this directory for full text. ### BEGIN INIT INFO # Provides: gearman-job-server # Required-Start: $network $remote_fs $syslog # Required-Stop: $network $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start daemon at boot time # Description: Enable gearman job server ### END INIT INFO prefix=/usr/local exec_prefix=${prefix} NAME=gearmand DAEMON=${exec_prefix}/sbin/gearmand PIDDIR=/var/run/gearman PIDFILE=${PIDDIR}/gearmand.pid GEARMANUSER="gearman" PARAMS="" test -x ${DAEMON} || exit 0 . /lib/lsb/init-functions test -f /etc/default/gearman-job-server && . /etc/default/gearman-job-server start() { log_daemon_msg "Starting Gearman Server" "gearmand" if ! test -d ${PIDDIR} then mkdir ${PIDDIR} chown ${GEARMANUSER} ${PIDDIR} fi if start-stop-daemon \ --start \ --exec $DAEMON \ -- --pid-file=$PIDFILE \ --user=$GEARMANUSER \ --daemon \ --log-file=/var/log/gearman-job-server/gearman.log \ $PARAMS then log_end_msg 0 else log_end_msg 1 log_warning_msg "Please take a look at the syslog" exit 1 fi } stop() { log_daemon_msg "Stopping Gearman Server" "gearmand" if test -e /tmp/gearman-job-server.sqlite then rm /tmp/gearman-job-server.sqlite fi if start-stop-daemon \ --stop \ --oknodo \ --exec $DAEMON \ --pidfile $PIDFILE then log_end_msg 0 else log_end_msg 1 exit 1 fi } status() { status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $? } case "$1" in start) start ;; stop) stop ;; status) status ;; restart|force-reload) stop start ;; *) echo "Usage: $0 {start|stop|restart|force-reload|status}" ;; esac ' > /etc/init.d/gearman-job-server ver1="1.1.0" echo -e "## Install php-gearman $ver1 ##" dpkg -r gearman sleep 1 wget http://pecl.php.net/get/gearman-${ver1}.tgz tar -zxvf gearman-${ver1}.tgz cd ./gearman-${ver1} phpize ./configure make checkinstall make clean cd ..

service gearman-job-server restart
service php5-fpm restart

Проверка

Ищем где находятся конфигурации расширений PHP

php --ini

Создаем файл ./gearman.ini и пишем в него следующее

extension=gearman.so

Проверяем правильность установки библиотеки

php --info | grep "gearman support"
gearman support => enabled

Использование

http://php.net/manual/ru/book.gearman.php

http://php.net/manual/ru/gearman.examples-reverse-bg.php

http://www.php.net/manual/ru/gearman.examples-reverse-task.php

http://highload.com.ua/index.php/2010/07/09/gearman-%D0%B8-php-%D0%B0%D1%81%D0%B8%D0%BD%D1%85%D1%80%D0%BE%D0%BD%D0%BD%D1%8B%D0%B5-%D0%B7%D0%B0%D0%B4%D0%B0%D1%87%D0%B8/

http://hotmania.ru/interesnye-it-novosti/gearman-i-php-asinxronnye-zadachi/

http://hotmania.ru/category/interesnye-it-novosti/page/11/

http://olemskoi.ru/node/3448