thinkphp 隊列 queue

php think queue:work --queue default_card(任務名稱) 單次執行

php think queue:listen --queue default_card 監聽:有任務進來時就執行。

 

三種情況:

  • queue:work 默認只執行一次隊列請求, 當請求執行完成後就終止;
  • queue:listen 監聽隊列請求, 只要運行着, 就能一直接受請求, 除非手動終止;
  • queue:work --daemon 同 listen 一樣, 只要運行着, 就能一直接受請求, 不一樣的地方是在這個運行模式下, 當新的請求到來的時候, 不重新加載整個框架, 而是直接 fire 動作.

能看出來, queue:work --daemon 是最高級的, 一般推薦使用這個來處理隊列監聽.

注意: 使用 queue:work --daemon , 當更新代碼的時候, 需要停止, 然後重新啓動, 這樣才能把修改的代碼應用上.

 

 

# yum install epel-release

# yum install -y supervisor

# systemctl enable supervisord # 開機自啓動

# systemctl start supervisord # 啓動supervisord服務

 

# systemctl status supervisord # 查看supervisord服務狀態

# ps -ef|grep supervisord # 查看是否存在supervisord進程

 

 

配置文件可以 這樣配置:

[program:queue_name]
command= /usr/local/bin/php think queue:listen --queue luck_draw
directory=項目路徑
;process_name=%(process_num)02d
;numprocs=5 ;啓動幾個進程
autostart=true ;隨着supervisord的啓動而啓動
autorestart=true ;自動啓動
startsecs=1 ;程序重啓時候停留在runing狀態的秒數
startretries=3 ;啓動失敗時的最多重試次數
redirect_stderr=true ;重定向stderr到stdout
stdout_logfile=/var/log/supervisor/tornado_server.log ;stdout文件

 

 

                                                                               如果覺得文章有幫助,點擊下方鏈接支持一下我吧~

                 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章