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就 ...
随机推荐
- SVN版本管理trunk及branch相关merge操作
先说说什么是branch.按照Subversion的说法,一个branch是某个development line(通常是主线也即trunk)的一个拷贝,见下图: branch存在的意义在于,在不干扰t ...
- win10安装软件被阻止后
以管理员身份运行CMD,然后在cmd里执行就可以了.
- [Flex] ButtonBar系列——最后一个项目的样式设置
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- [SQL]SUTFF内置函数的用法
STUFF 删除指定长度的字符并在指定的起始点插入另一组字符. 语法 STUFF ( character_expression , start , length , character_express ...
- (medium)LeetCode 220.Contains Duplicate III
Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...
- [POJ 1385] Lifting the Stone (计算几何)
题目链接:http://poj.org/problem?id=1385 题目大意:给你一个多边形的点,求重心. 首先,三角形的重心: ( (x1+x2+x3)/3 , (y1+y2+y3)/3 ) 然 ...
- Spring Data Jpa 规范接口表
Keyword Sample JPQL snippet And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname ...
- wap资费页面
移动网关 CMWAP 返回vnd.wap.wml 用CMWAP接入点发一个http的请求时,移动的10.0.0.172这个代理网关会回一个确认页面,中国特色.处理的办法是检测到Content-type ...
- ua实现类似 www.taobao.com 在手机上打开自动转变为 m.taobao.com 的域名转换
user-agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.25 ...
- ASP.Net软件工程师基础(三)
1.多态 答: (1)虚方法 public class Child : Person { public void Speach() { base.Speach(); } public virtual ...