Gearman安装及使用
基础安装包
- yum install vim wget gcc gcc-c++ make dos2unix gperf libevent libevent-devel zlib-devel bzip2-devel openssl-devel ncurses-devel boost boost-devel mysql-devel
安装gearman 异步队列
- # wget https://launchpad.net/gearmand/1.2/1.1.9/+download/gearmand-1.1.9.tar.gz
- # tar -zxvf gearmand-1.1.9.tar.gz
- # cd gearmand-1.1.9
- # ./configure 如果出现错误请查看下面的错误解决
成功后如下
- * LIBS:
- * LDFLAGS Flags:
- * Assertions enabled: no
- * Debug enabled: no
- * Warnings as failure: no
- * Building with libsqlite3 no
- * Building with libdrizzle no
- * Building with libmemcached not found
- * Building with libpq no
- * Building with tokyocabinet no
- * Building with libmysql yes
- * SSL enabled: no
- * make -j: 3
- * VCS checkout: no
- # make
- # make install
安装gearman php 扩展
- # wget http://pecl.php.net/get/gearman
- # mv gearman gearman.tar.gz
- # tar -zxvf gearman.tar.gz
- # cd gearman-1.1.2/
- # phpize
- # ./configure
- # make
- # make install
- # cd /etc/php.d/
- # cp gd.ini gearman.ini
- # vim gearman.ini
- ; Enable gearman extension module
- extension=gearman.so
- # service php-fpm restart
错误解决
在configure过程中出现了以下错误:
- checking for Boost headers version >= 1.39.0… no
- configure: error: cannot find Boost headers version >= 1.39.0
解决办法:
- # yum search boost
- # yum install boost.x86_64
- # yum install boost-devel.x86_64
继续执行./configure出现以下错误
- checking for gperf... no
- configure: error: could not find gperf
解决办法:
- #yum search gperf
- #yum install gperf.x86_64
继续执行./configure出现以下错误
- checking test for a working libevent... no
- configure: error: Unable to find libevent
解决办法:
- # yum install libevent libevent-devel
gearman 参数说明
- Client mode: gearman [options] [<data>]
- Worker mode: gearman -w [options] [<command> [<args> ...]]
- Common options to both client and worker modes.
- -f <function> - Function name to use for jobs (can give many)
- -h <host> - Job server host
- -H - Print this help menu
- -v - Print diagnostic information to stdout(false)
- -p <port> - Job server port
- -t <timeout> - Timeout in milliseconds
- -i <pidfile> - Create a pidfile for the process
- Client options:
- -b - Run jobs in the background(false)
- -I - Run jobs as high priority
- -L - Run jobs as low priority
- -n - Run one job per line(false)
- -N - Same as -n, but strip off the newline(false)
- -P - Prefix all output lines with functions names
- -s - Send job without reading from standard input
- -u <unique> - Unique key to use for job
- Worker options:
- -c <count> - Number of jobs for worker to run before exiting
- -n - Send data packet for each line(false)
- -N - Same as -n, but strip off the newline(false)
- -w - Run in worker mode(false)
gearman异步队列使用:
下面先做个命令行测试:
首先开两个命令行窗口:
tty1:
- # gearman -w -f abc -- wc -m
表示统计用户输入了多少个字符。
tty2:
- # gearman -f abc 'aaaa'
4
输出结果正确。
# gearman -f abc < /etc/php.ini
当然也可以直接从文件中读入内容。