zoukankan      html  css  js  c++  java
  • Yii2.0 安装yii2-queue并在Linux启动守护进程监听消息

    一、什么是yii2-queue?

    Yii2-queue是Yii2.0 PHP框架下一个消息队列拓展插件,支持基于DB, Redis, RabbitMQ, AMQP, Beanstalk 和 Gearman等。yii2-queue GitHub地址:https://github.com/yiisoft/yii2-queue

    二、如何安装yii2-queue?

    php composer.phar require --prefer-dist yiisoft/yii2-queue

    三、Linux systemd介绍

    systemd是linux下的一款系统和服务管理器,为什么要使用systemd ? 在rpm包二进制方式安装的linux软件中,使用init守护进程进行服务状态的管理或者使用service命令 例如启动Mysql数据库可以是 /etc/init.d/mysql start 或者service mysql start.

    使用linux init进程进行管理服务的时候有两个缺点:

      1.init系统进程是串行执行的,也就是同步的 ,只有前一个进程启动完成,才会启动下一进程。

      2.启动脚步复杂,init进程是只执行启动脚步,不管其他的任务

    使用Systemd优点:

      1.Systemd支持并行化任务,

      2.同时采用socket于D-Bus总线式激活服务,按需启动守护进程(daemon)

    在新版的Linux系统中都在使用sytemd 进行管理 例如(Ubuntu 16、Debian 8、CentOS 7)

    四、在Linux创建systemd系统服务监听队列消息

    1、在Linux下进入system目录,相关命令:cd /etc/systemd/system;

    2、新增yii-queue@.service文件,相关命令:vi yii-queue@.service;

    3、yii-queue@.service文件内容如下:

    [Unit]
    Description=Yii Queue Worker %I
    After=network.target
    # the following two lines only apply if your queue backend is mysql
    # replace this with the service that powers your backend
    After=mysql.service
    Requires=mysql.service
    
    [Service]
    User=www-data
    Group=www-data
    ExecStart=/usr/bin/php /var/www/my_project/yii queue/listen --verbose
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target

    4、重载systemd配置文件使其生效,相关命令:systemctl daemon-reload;

    5、其他相关命令:

    # To start two workers
    systemctl start yii-queue@1 yii-queue@2
    
    # To get the status of running workers
    systemctl status "yii-queue@*"
    
    # To stop a specific worker
    systemctl stop yii-queue@2
    
    # To stop all running workers
    systemctl stop "yii-queue@*"
    
    # To start two workers at system boot
    systemctl enable yii-queue@1 yii-queue@2
  • 相关阅读:
    【微信小程序】---线上环境搭建
    【vue】---项目接口管理---【巷子】
    【微信小程序】---授权登陆---【巷子】
    【react】---17新增的生命周期
    laravel 管道设计模式
    vim相关
    OAuth 2.0及微信网页授权
    linux下目录的读、写、执行权限辨析
    NIM游戏
    姿态角(欧拉角)yaw、pitch、roll语义解释
  • 原文地址:https://www.cnblogs.com/itsharehome/p/10041716.html
Copyright © 2011-2022 走看看