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学习笔记二(配置)的更多相关文章

  1. Struts2学习笔记二 配置详解

    Struts2执行流程 1.简单执行流程,如下所示: 在浏览器输入请求地址,首先会被过滤器处理,然后查找主配置文件,然后根据地址栏中输入的/hello去每个package中查找为/hello的name ...

  2. Struts2学习笔记(二)——配置详解

    1.Struts2配置文件加载顺序: default.properties(默认常量配置) struts-default.xml(默认配置文件,主要配置bean和拦截器) struts-plugin. ...

  3. 转:C#制作ORM映射学习笔记二 配置类及Sql语句生成类

    在正式开始实现ORM之前还有一点准备工作需要完成,第一是实现一个配置类,这个很简单的就是通过静态变量来保存数据库的一些连接信息,等同于.net项目中的web.config的功能:第二需要设计实现一个s ...

  4. JMX学习笔记(二)-Notification

    Notification通知,也可理解为消息,有通知,必然有发送通知的广播,JMX这里采用了一种订阅的方式,类似于观察者模式,注册一个观察者到广播里,当有通知时,广播通过调用观察者,逐一通知. 这里写 ...

  5. InterSystems Ensemble学习笔记(二) Ensemble创建镜像, 实现自动故障转移

    系列目录 InterSystems Ensemble学习笔记(一) Ensemble介绍及安装InterSystems Ensemble学习笔记(二) Ensemble创建镜像, 实现自动故障转移 一 ...

  6. kvm虚拟化学习笔记(二)之linux kvm虚拟机安装

    KVM虚拟化学习笔记系列文章列表----------------------------------------kvm虚拟化学习笔记(一)之kvm虚拟化环境安装http://koumm.blog.51 ...

  7. amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules

    amazeui学习笔记二(进阶开发5)--Web 组件开发规范Rules 一.总结 1.见名知意:见那些class名字知意,见函数名知意,见文件名知意 例如(HISTORY.md Web 组件更新历史 ...

  8. JDBC学习笔记二

    JDBC学习笔记二 4.execute()方法执行SQL语句 execute几乎可以执行任何SQL语句,当execute执行过SQL语句之后会返回一个布尔类型的值,代表是否返回了ResultSet对象 ...

  9. ZooKeeper学习笔记二:API基本使用

    Grey ZooKeeper学习笔记二:API基本使用 准备工作 搭建一个zk集群,参考ZooKeeper学习笔记一:集群搭建. 确保项目可以访问集群的每个节点 新建一个基于jdk1.8的maven项 ...

  10. MongoDB学习笔记二- Mongoose

    MongoDB学习笔记二 Mongoose Mongoose 简介 之前我们都是通过shell来完成对数据库的各种操作, 在开发中大部分时候我们都需要通过程序来完成对数据库的操作 而Mongoose就 ...

随机推荐

  1. 通过JSTL+EL实现循环迭代

    使用前需要导入包 jstl.jar 和 standard.jar <%@ page language="java" import="java.util.*,com. ...

  2. 使用系统UITabbarItem自定义图片显示原本颜色和自定义文字颜色

    ...... ThirdViewController *thirdVC = [[ThirdViewControlleralloc]initWithTitle:@"搜索信息"]; / ...

  3. [ActionScript 3.0] flash如何访问父级或者舞台上的变量、函数等的方法

    方法一: 进行类型转换,先将root.parent强制转换为MovieClip类型,再进行使用,如下:MovieClip(root).i.MovieClip(this.parent).i.MovieC ...

  4. MVC 4 与WebForm 混合应用 WebApi 发布常见问题

    1.所有应用的MVC相关程序集编译时要选择复制到本地,需要用到的程序如下图 2.IIS设置: 因为 IIS 7/8 采用了更安全的 web.config 管理机制,默认情况下会锁住配置项不允许更改.运 ...

  5. [SQJ]sql如何实现类似统计的功能

    假设mssql2000中, 有如下表: table Class class_No course_Name ----------------------------------- chinese mat ...

  6. UTF-8 GB2321

    已知:汉字“你”UTF8编码是 0xe4bda0,GBK编码是 0xc4e3,求证. 0xe4bda0 → 2进制11100100 10111101 10100000 → UTF8 3字节111001 ...

  7. nginx 添加perl

    首先,要知道你原安装的nginx版本,以及原来安装的模块,用nginx -V即可 /usr/sbin/nginx -V 结尾处的--add-module 重新安装时这里可以去掉, 然后去官网下载一个相 ...

  8. Windows操作 - Photoshop为图片添加透明立体水印

    原文地址:http://design.yesky.com/photoshop/252/2427752.shtml 本文我们介绍用Photoshop为图片添加透明立体水印的方法和技巧. 原图: 打开原图 ...

  9. C程序之修改Windows的控制台颜色(转载)

    Windows的CMD可以和Linux下的终端一样可以有五颜六色,目前我在网上找到2种方法可以修改Windows的CMD,当然都是在代码中修改的.在“CMD”->“属性”->“颜色”,这种 ...

  10. 在java 中,数组与 List<T> 类型的相互转换

    在java中,数组与List<T> 之前进行互相转换,转换方法可总结为以下几种: 一. 将 数组转换成List<T> 1. 使用 Collections 的addAll 方法 ...