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."\n\n";
3:workers 目录:/usr/local/nginx/resque-worker
sendmail.php
<?php
class SendMail{ public function perform(){
file_put_contents(__DIR__.'/sendmail.txt',date('Y-m-d H:i:s').PHP_EOL,FILE_APPEND);
} }
4:添加常驻进程
#!/bin/bash #
### BEGIN INIT INFO
# Provides: php-resque
# Default-Start:
# Default-Stop:
# 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=
export VVERBOSE= # for debugging
export REDIS_BACKEND=localhost:
#. /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 -
}
kill() {
ps -ef | grep resque | grep -v grep | grep -v resque-web | awk '{print $2}' | xargs kill -
}
case "$1" in
start)
number=$(ps aux | grep php-resque/bin/resque.php | grep -v grep | wc -l)
if [ $number -gt ]
then
echo "php-resque is running. ($number workers)"
echo "You may wanna stop them before you start."
else
start
fi
;; stop)
stop
;; kill)
kill
;; status)
number=$(ps aux | grep php-resque/bin/resque.php | grep -v grep | wc -l)
if [ $number -gt ]
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 '<pre>';
print_r($job);
echo '</pre>';
die('FILE:' . __FILE__ . '; LINE:' . __LINE__);
} }
php-resque学习笔记二(配置)的更多相关文章
- Struts2学习笔记二 配置详解
		Struts2执行流程 1.简单执行流程,如下所示: 在浏览器输入请求地址,首先会被过滤器处理,然后查找主配置文件,然后根据地址栏中输入的/hello去每个package中查找为/hello的name ... 
- Struts2学习笔记(二)——配置详解
		1.Struts2配置文件加载顺序: default.properties(默认常量配置) struts-default.xml(默认配置文件,主要配置bean和拦截器) struts-plugin. ... 
- 转:C#制作ORM映射学习笔记二 配置类及Sql语句生成类
		在正式开始实现ORM之前还有一点准备工作需要完成,第一是实现一个配置类,这个很简单的就是通过静态变量来保存数据库的一些连接信息,等同于.net项目中的web.config的功能:第二需要设计实现一个s ... 
- JMX学习笔记(二)-Notification
		Notification通知,也可理解为消息,有通知,必然有发送通知的广播,JMX这里采用了一种订阅的方式,类似于观察者模式,注册一个观察者到广播里,当有通知时,广播通过调用观察者,逐一通知. 这里写 ... 
- InterSystems Ensemble学习笔记(二) Ensemble创建镜像, 实现自动故障转移
		系列目录 InterSystems Ensemble学习笔记(一) Ensemble介绍及安装InterSystems Ensemble学习笔记(二) Ensemble创建镜像, 实现自动故障转移 一 ... 
- kvm虚拟化学习笔记(二)之linux kvm虚拟机安装
		KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ... 
- amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules
		amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules 一.总结 1.见名知意:见那些class名字知意,见函数名知意,见文件名知意 例如(HISTORY.md Web 组件更新历史 ... 
- JDBC学习笔记二
		JDBC学习笔记二 4.execute()方法执行SQL语句 execute几乎可以执行任何SQL语句,当execute执行过SQL语句之后会返回一个布尔类型的值,代表是否返回了ResultSet对象 ... 
- ZooKeeper学习笔记二:API基本使用
		Grey ZooKeeper学习笔记二:API基本使用 准备工作 搭建一个zk集群,参考ZooKeeper学习笔记一:集群搭建. 确保项目可以访问集群的每个节点 新建一个基于jdk1.8的maven项 ... 
- MongoDB学习笔记二- Mongoose
		MongoDB学习笔记二 Mongoose Mongoose 简介 之前我们都是通过shell来完成对数据库的各种操作, 在开发中大部分时候我们都需要通过程序来完成对数据库的操作 而Mongoose就 ... 
随机推荐
- redis info命令详解
			以一种易于解释(parse)且易于阅读的格式,返回关于 Redis 服务器的各种信息和统计数值. 通过给定可选的参数 section ,可以让命令只返回某一部分的信息: server : 一般 Red ... 
- JSON.stringify()的使用--将string转换成json
			===========================================================1. ====JSON.stringify()================== ... 
- arp -s 157.55.85.212   00-aa-00-62-c6-09  .... Adds a static entry.
			ARp是一个重要的TCp/Ip协议,并且用于确定对应Ip地址的网卡物理地址.实用arp命令,我们能够查看本地计算机或另一台计算机的ARp高速缓存中的当前内容.此外,使用arp命令,也可以用人工方式输入 ... 
- [kuangbin带你飞]专题十二 基础DP1
			ID Origin Title 167 / 465 Problem A HDU 1024 Max Sum Plus Plus 234 / 372 Problem B HDU 1 ... 
- BC之Run
			Problem Description AFA is a girl who like runing.Today,he download an app about runing .The app can ... 
- Android--创建进度框ProgressDialog
			1.布局文件progress_dialog_activity.xml <?xml version="1.0" encoding="utf-8"?> ... 
- es增量自定义更新的脚本
			安装需要可软件 sudo apt-get install python-pip sudo pip install elasticsearch; sudo apt-get install python- ... 
- Codeforces Round #218 (Div. 2) D. Vessels
			D. Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ... 
- Android:Activity的跳转
			// 实际开发中常用的方法 Intent intent = new Intent(); intent.setClass(MainActivity.this, LoginActivity.class); ... 
- CSS3 border-radius 属性和CSS outline 属性
			CSS3 border-radius 属性 border-radius 属性是一个简写属性,用于设置四个 border-*-radius 属性. 提示:该属性允许为元素添加圆角边框! 注释:按此顺序设 ... 
