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就 ...
随机推荐
- centos 6.5 安装 buildbot-slave 0.8.9
公司服务器多数都用的centos,这个是大环境,改不了,只好研究怎么安装buildbot-slave. buildbot-master倒是没有问题,可控,自己弄了一个ubuntu14来玩. cento ...
- (*medium)LeetCode 211.Add and Search Word - Data structure design
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- [HDU 3689]Infinite monkey theorem (KMP+概率DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3689 黄老师说得对,题目只有做wa了才会有收获,才会有提高. 题意:一个猴子敲键盘,键盘上有n个键,猴 ...
- Hdfs增量导入小文件合并的思路
1.使用mr进行合并 2.使用getmerge 将文件拉取到本地,再上传到hdfs,注意nl参数 3.使用appendToFile 4.使用hadoop提供的打包压缩技术 Usage: hadoop ...
- 【原】dnsmasq小工具
1.介绍 DNSmasq是一个轻巧的,容易使用的DNS服务工具,它可以应用在内部网和Internet连接的时候的IP地址NAT转换,也可以用做小型网络的DNS服务. 它可以提供如下几个实用的功能: 1 ...
- 【转】nginx配置location总结及rewrite规则写法
原文:http://seanlook.com/2015/05/17/nginx-location-rewrite/ 1. location正则写法 location = / { # 精确匹配 / ,主 ...
- ASP.NET MVC开发微信(一)
public string index() { return Content(""); }
- ExtJS 4.2 中自定义事件
前台HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www ...
- OC基础(4)
NSString 类介绍及用法 结构体成员变量 对象和方法之间的关系 对象作为方法的参数连续传递 *:first-child { margin-top: 0 !important; } body &g ...
- VS error retrieving information from user datastore
搭建好VS2005+PB6.0的开发环境后,新建MFC智能设备应用程序工程出错,错误信息如下: error retrieving information from user datastore 很奇怪 ...