简体   繁体   English

Laravel + Beanstalkd:如何运行“queue:listen”作为服务

[英]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: 这将执行以下操作:

  • Give the queue worker a unique name 为队列工作者指定一个唯一的名称
  • Run the php artisan queue:work command 运行php artisan queue:work命令
  • Automatically start the queue worker on system restart and automatically restart the queue workers should they fail 在系统重新启动时自动启动队列工作程序,并在队列失败时自动重新启动它们
  • Run the queue worker across eight processes (this can be increased or reduced depending on your needs) 跨八个进程运行队列工作程序(可根据您的需要增加或减少)
  • Log any output to /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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM