php resque 分布式,php-resque学习笔记二(配置)

1:前提

系统:CentOS

PHP版本:PHP7     安装目录:/usr/local/php

php-resque          安装目录:/home/software/php-resque

worker                存放目录:/usr/local/nginx/resque-worker

2:job   /home/software/php-resque/demo/queue.php

if(empty($argv[1])) {die('Specify the name of a job to add. e.g, php queue.php PHP_Job');

}require __DIR__ . '/init.php';

date_default_timezone_set('PRC');

Resque::setBackend('localhost:6379');//You can also use a DSN-style format:

//Resque::setBackend('redis://user:pass@127.0.0.1:6379');

//Resque::setBackend('redis://user:pass@a.host.name:3432/2');

$args = array('time' => time(),

'array' => array('test' => 'test',),);$jobId = Resque::enqueue('default', $argv[1], $args, true);echo "Queued job ".$jobId."

";

3:workers       目录:/usr/local/nginx/resque-worker

sendmail.php

}

}

4:添加常驻进程

#!/bin/bash

#

### BEGIN INIT INFO

# Provides: php-resque

# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: Start and stop the php-resque service daemon

# Description: Controls the main php-resque service daemon "php-resque"### END INIT INFO

#

export APP_INCLUDE=/usr/local/nginx/resque-worker/require.php

export QUEUE=default

export COUNT=1export VVERBOSE=1 # fordebugging

export REDIS_BACKEND=localhost:6379#./etc/rc.d/init.d/functions

start() {su -s /bin/bash www-data -c "/usr/local/php/bin/php /home/software/php-resque/bin/resque.php > /var/log/php-resque.log 2>&1" su -s /bin/bash www-data -c "/usr/local/php/bin/php /home/software/php-resque/demo/resque.php > /var/log/php-resque.log 2>&1" &}

stop() {ps -ef | grep resque | grep -v grep | grep -v resque-web | awk '{print $2}' | xargs kill -15}kill() {ps -ef | grep resque | grep -v grep | grep -v resque-web | awk '{print $2}' | xargs kill -9}case "$1" instart)

number=$(ps aux | grep php-resque/bin/resque.php | grep -v grep | wc -l)if [ $number -gt 0]then

echo "php-resque is running. ($number workers)"

echo "You may wanna stop them before you start."

elsestartfi;;

stop)

stop

;;kill)kill;;

status)

number=$(ps aux | grep php-resque/bin/resque.php | grep -v grep | wc -l)if [ $number -gt 0]then

echo "php-resque is running. ($number workers)"

else

echo "php-resque is not running."

fi;;*)echo -n "Usage: $0 {start|stop|status}"

esac

5:移到php项目中

cp -R  /home/software/php-resque  /usr/local/nginx/www/protected/vendor/php-resque

6:在控制器里调用  vim /usr/local/nginx/www/protected/conterollers/ResqueController.php

/**

* Description of ResqueController

*

* @author dxh20012012001@sina.com

*/

class ResqueController extends Controller {

//put your code here

public function actionIndex() {

Yii::import('application.vendor.php-resque.vendor.autoload', true);

$resque = new Resque();

$resque->setBackend('127.0.0.1:6381');

$job = $resque->enqueue('default', 'SendMail');

echo '

';

print_r($job);

echo '

';

die('FILE:' . __FILE__ . '; LINE:' . __LINE__);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值