Php-Redis 邮件队列实现总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wjc19911118/article/details/50754436

1. php- redis 实现的队列相关文章

https://github.com/vincenthou/vincenthou.github.io/issues/17

https://github.com/chrisboulton/php-resque/issues/32

http://www.cnblogs.com/zl0372/p/PHP-Resque2.html

http://blog.hsatac.net/2012/01/php-resque-introduction/

http://www.cnblogs.com/zl0372/p/3696641.html

http://www.yiiframework.com/extension/yii-resque/

http://git.oschina.net/VincentHou/yii-resque-ex#git-readme

2.安装ruby监控程序,监控处理队列任务的workers

  1. 安装
    gem install resque
  2. 运行
    resque-web -p 3000
    resque-web -p 3001 -r redis://user:[email protected]:6379 -d
  3. 访问
    访问:127.0.0.1:3000

3.使用redis-cli连接redis

redis-cli -h 127.0.0.1 -p 6379 都为默认值可以省略
auth redis-pass 验证有密码的redis server

redis 带密码的停止服务

  • redis-cli -p 6379 -a 654321 shutdown

4.单独设置worker启动

  1. 启动
    1. ./yiic rresque start --queue=email,sms[*] --interval=2 --verbose=0 --count=2
    2. interval 的意思是如果当前队列里面没有内容,会睡眠多长时间
  2. 停止所有
    1. ./yiic rresque stop

5.启动管理worker进程的进程supervisord

  1. 启动
    supervisord -c /etc/supervisor/supervisord.conf
  2. 停止
    1. supervisorctl -uadmin -padmin
    2. reload 重新加载supervisord的配置文件【/etc/supervisor/supervisord.conf】
  3. 将worker进程添加到supervisord,使用supervisord管理
    1. 该方案不行, supervisord只能监控后台守护程序

6.redis中的队列信息存储

1. 失败job的记录

  1. 获取失败的job数量 字符串类型
    get resque:stat:failed

  2. 获取job错误的详细信息 list类型
    LRANGE resque:failed 0 -1

2. worker相关信息 hash类型

  1. 获取worker日志存储的位置
    HGETALL workerLogger
  2. 获取某一个worker的处理任务数量 字符串类型
    get resque:stat:processed:evolution-ThundeRobot:20677:sms[jobname]
  3. 获取某个worker的启动时间 字符串类型
    get resque:worker:evolution-ThundeRobot:13598:sms:started

3. 任务相关

  1. 任务列表list类型
    1. 获取长度: LLEN resque:queue:email[jobname]
    2. 查看所有的详细内容 LRANGE resque:queue:email[jobname] 0 -1
  2. 获取每个任务的状态信息
    get resque:job:1e46c7a14b15700f271c5cec53d26511:status 字符串类型

4. 队列类型相关信息【email sms other……】 Set集合类型

  1. 获取当前队列类型的个数
    SCARD resque:queues
  2. 获取当前都有那些类型的队列
    SMEMBERS resque:queues

7.Yii配置有关

1. console.php

//base
    'sourceLanguage'=>'en_us,zh_cn',
    'language'=>'zh_cn',

//components
    'resque'=>array(
        'class' => 'application.components.yii-resque.RResque',
        'server' => 'localhost',     // Redis server address
        'port' => '6379',            // Redis server port
        'database' => 0,             // Redis database number
        'password' => '',            // Redis password auth, set to '' or null when no auth needed
        'includeFiles' => array(),    // Absolute path of files that will be included when initiate queue
        'loghandler' => 'RotatingFile', // Monolog handler type without "handler"
        'logtarget' => '/var/log/mylog', // Target log file or configuration (please refer to logging section)
    ),

2. 邮件配置

<?php

return array(
    'viewPath' => 'application.views.mail',
    'layoutPath' => 'application.views.layouts',
    'baseDirPath' => 'webroot.images.mail', //note: 'webroot' alias in console apps may not be the same as in web apps
    'savePath' => 'webroot.assets.mail',
    'testMode' => false,
    'layout' => 'mail',
    'CharSet' => 'UTF-8',
    'AltBody' => Yii::t('YiiMailer', 'You need an HTML capable viewer to read this message.'),
    'language' => array(
        'authenticate' => Yii::t('YiiMailer', 'SMTP Error: Could not authenticate.'),
        'connect_host' => Yii::t('YiiMailer', 'SMTP Error: Could not connect to SMTP host.'),
        'data_not_accepted' => Yii::t('YiiMailer', 'SMTP Error: Data not accepted.'),
        'empty_message' => Yii::t('YiiMailer', 'Message body empty'),
        'encoding' => Yii::t('YiiMailer', 'Unknown encoding: '),
        'execute' => Yii::t('YiiMailer', 'Could not execute: '),
        'file_access' => Yii::t('YiiMailer', 'Could not access file: '),
        'file_open' => Yii::t('YiiMailer', 'File Error: Could not open file: '),
        'from_failed' => Yii::t('YiiMailer', 'The following From address failed: '),
        'instantiate' => Yii::t('YiiMailer', 'Could not instantiate mail function.'),
        'invalid_address' => Yii::t('YiiMailer', 'Invalid address'),
        'mailer_not_supported' => Yii::t('YiiMailer', ' mailer is not supported.'),
        'provide_address' => Yii::t('YiiMailer', 'You must provide at least one recipient email address.'),
        'recipients_failed' => Yii::t('YiiMailer', 'SMTP Error: The following recipients failed: '),
        'signing' => Yii::t('YiiMailer', 'Signing Error: '),
        'smtp_connect_failed' => Yii::t('YiiMailer', 'SMTP Connect() failed.'),
        'smtp_error' => Yii::t('YiiMailer', 'SMTP server error: '),
        'variable_set' => Yii::t('YiiMailer', 'Cannot set or reset variable: ')
    ),
// if you want to use SMTP, uncomment and configure lines below to your needs
    'Mailer' => 'smtp',
    'Host' => 'smtp.office365.com',
    'Port' => 587,
    'SMTPSecure' => 'tls',
    'SMTPAuth' => true,
    'Username' => '[email protected]',
    'Password' => 'LByzHC=:N2',
);

3.mail->smtp设置

    public function setSmtp($host='localhost',$port=25, $secure='', $auth=false, $username='', $password='')
    {
        $this->isSMTP();
        $this->Host = $host;
        $this->Port = $port;
        $this->SMTPSecure = $secure;
        $this->SMTPAuth = $auth;
        $this->Username = $username;
        $this->Password = $password;
        $this->CharSet  = "UTF-8"; //字符集
        $this->Encoding = "base64"; //编码方式
        $this->isHTML(true);
    }

猜你喜欢

转载自blog.csdn.net/wjc19911118/article/details/50754436