ww7618 发表于 2015-7-21 07:23:06

Redis+php-resque实现消息队列

  服务器硬件配置

Dell PowerEdge R310英特尔单路机架式服务器

[*]Intel Xeon Processor X3430 2.4GHz, 8MB Cache
[*]8GB内存(2 x 4GB), 1333MHz, 双列RDIMMs用1于处理器配置
[*]2TB近线3.5英寸7.2K RPM 6Gbps SAS硬盘 - 非热插拔
[*]SAS 6/iR 控制卡
[*]8倍速SATA超薄DVD-ROM光驱
[*]非冗余电源,350W
  
软件环境

[*]CentOS 6.2 minimal
[*]Nginx 1.2.7
[*]PHP 5.3.17
[*]MySQL 5.5.28-log
[*]Redis 2.6.16
  
一、Redis安装
1. 获取源码
  shell>#cd /usr/local/src
shell># wget http://download.redis.io/releases/redis-2.6.16.tar.gz
shell># tar -zxvf redis-2.6.16.tar.gz
shell># cd redis-2.6.16
2. 编译、安装
  shell>#make
3. 配置Redis
  编辑redis.conf文件
  shell>#vi /usr/local/src/redis-2.6.16/redis.conf
  daemonize= yes
4. 启动Redis
  shell>#src/redis-server/usr/local/src/redis-2.6.16/redis.conf


5. 测试连接
  shell>#src/redis-cli


  redis>set foo bar
  OK
  redis>get foo
  “bar”
  redis>exit;
  
二、phpredis 安装
1. 获取源码
  shell>#cd /usr/local/src
  
shell># wget https://github.com/nicolasff/phpredis/archive/2.2.3.tar.gz -Onicolasff-phpredis-2.2.3.tar.gz
  
shell># tar -zxvf nicolasff-phpredis-2.2.3.tar.gz
  
shell># cd phpredis-2.2.3
2. 编译、安装
  shell>#/usr/local/php/bin/phpize
  
  shell>#./configure –-with-php-config=/usr/local/php/bin/php-config
  
  shell># make &&make install
3. 配置php.ini
  shell>#vi/usr/local/php/etc/php.ini
  
extension=redis.so
4. 重启nginx & php-fpm
  
三、php-resque安装
  *准备工作
  需要pcntl支持
  安装git
  shell>#yum -y install git
  安装Composer
  shell>#cd/usr/local/bin
  
shell># curl–sS https://getcomposer.org/installer| php
  
  shell># mv composer.phpar/usr/local/bin/composer
  
  
  修改 php.ini
  
  disable_functions = … …
  
  将proc_open和proc_get_status以及exec删除
  
  保存后,重启LNMP
  
1. 获取源码
  shell>#cd /home/wwwroot/default
  
shell># gitclone git://github.com/chrisboulton/php-resque.git
  


2. 安装
  shell>#cd php-resque
  
shell># composer install
  
  
  

四、Demo
1. 一个Job
  Job|任务:一个Job就是一个需要在后台完成的任务,比如邮件发送,就可以抽象为一个Job。在Resque中一个Job就是一个Class。
  
  shell># cd php-resque
  
shell># vimdemo/job.php
  
  
页: [1]
查看完整版本: Redis+php-resque实现消息队列