自动运行Laravel队列 [英] Running Laravel queues automatically

查看:589
本文介绍了自动运行Laravel队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了 Laravel 队列.问题是我必须每次都运行命令php artisan queue:listen.是否有任何方式可以在不运行任何命令的情况下自动执行作业.

I have implemented Laravel queue.The thing is i have to run the command php artisan queue:listen every time.Is there any way that the jobs get executed automatically without running any command.

推荐答案

在这里,您可以在crontab中放入一个单行代码(让它每5分钟运行一次):

Here's a one-liner to put into your crontab (let it run, let say, every 5 minutes):

cd /path/to/your/project && jobs -l | grep `cat queue.pid` || { nohup /usr/bin/php artisan queue:listen & echo $! > queue.pid; }

这里有两个变量: 1. /path/to/your/project-是您的Laravel项目根目录.有效地是php artisan所在的文件夹; 2. /usr/bin/php-服务器上PHP可执行文件的路径(which php)

two variables here: 1. /path/to/your/project -- is your Laravel project root. Effectively, the folder, where php artisan would work; 2. /usr/bin/php -- path to PHP executable on the server (which php)

这篇关于自动运行Laravel队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆