[英]Laravel + Beanstalkd: How to run “queue:listen” as a service
I'm using Beanstalkd as a work queue in my project. 我在项目中使用Beanstalkd作为工作队列。
Now, my project is completed and I have to deploy it on VPS(production server). 现在,我的项目已经完成,我必须将其部署在VPS(生产服务器)上。
There is something that confusing me! 有些让我困惑的事情! should I ssh to production server and manually type
php artisan queue:listen
? 我应该ssh到生产服务器并手动输入
php artisan queue:listen
? (it's crap) (这是垃圾)
Is there any server to run queue:listen
as service? 有没有服务器来运行
queue:listen
服务?
You should use something like Supervisor to run the queue in production. 您应该使用Supervisor之类的东西在生产中运行队列。 This will allow you to run the process in the background, specify the number of workers you want processing queued jobs and restart the queue should the process fail.
这将允许您在后台运行该进程,指定要处理排队作业的工作器数,并在进程失败时重新启动队列。
As for the queue you choose to use, that's up to you. 至于你选择使用的队列,这取决于你。 In the past I've used Beanstalkd locally installed on an instance and Amazon SQS.
在过去,我已经在实例和Amazon SQS上本地安装了Beanstalkd。 The local instance was fine for basic email sending and other async tasks, SQS was great for when the message volume was massive and needed to scale.
本地实例适用于基本的电子邮件发送和其他异步任务,SQS非常适用于消息量巨大且需要扩展的情况。 There are other SaaS products too such as IronMQ, but the usual reason people run into issues in production are because they're not using Supervisor.
还有其他SaaS产品,如IronMQ,但人们在生产中遇到问题的通常原因是因为他们没有使用Supervisor。
You can install Supervisor with apt-get
. 您可以使用
apt-get
安装Supervisor。 The following configuration is a good place to start: 以下配置是一个很好的起点:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/forge/app.com/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
numprocs=8
stdout_logfile=/home/user/app.com/worker.log
This will do the following: 这将执行以下操作:
php artisan queue:work
command php artisan queue:work
命令 /home/user/app.com/worker.log
/home/user/app.com/worker.log
To start Supervisor, you'd run the following (after re-reading the configuration/restarting): 要启动Supervisor,您将运行以下命令(重新读取配置/重新启动后):
sudo supervisorctl start laravel-worker:*
The documentation gives you some more in-depth information about using Supervisor to run Laravel's queue processes. 该文档为您提供了有关使用Supervisor运行Laravel队列进程的更深入信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.