laravel队列-同步驱动程序如何工作?它是在单独的进程中还是在主执行线程中执行? [英] laravel queues - how sync driver works? Does it executes in a seperated process or the main execution thread?

查看:164
本文介绍了laravel队列-同步驱动程序如何工作?它是在单独的进程中还是在主执行线程中执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从服务器发送推送通知,并希望仅在后台进程中执行它.我已经阅读了Laravel文档,并且了解数据库驱动程序和其他一些选项.我已经将其与本地计算机上的数据库驱动程序一起使用,但是有一件事使我烦恼,我必须启动一个后台线程来侦听使用php artisan queue:listen --deamon添加到队列中的作业.

关键是,它总是像"crone"任务一样运行,从而消耗了我的一些资源和内存.我只想在触发推送通知时创建一个新进程,它应该在添加后立即开始执行,然后关闭该进程.另一方面,对于laravel作业,我总是必须运行一个我希望避免的后台进程,而且我正在使用共享主机,该主机不允许我在服务器上安装"supervisor"来监视我的作业执行情况.

任何人都可以消除这种歧义吗?处理这种情况的更好方法是什么?

解决方案

经过研究,我决定使用database驱动程序.还有其他一些不错的选择,但是选择将取决于您的系统工作负载.

要点是,sync驱动程序使用主线程来执行任务,这仅在您处于开发状态时才有用.如果您有生产系统,则可能需要考虑其他一些选项来运行队列.排队长时间运行的任务的主要思想是能够在某些后台进程中执行它们,这样您的主应用程序线程就不会阻塞,并且您可以更快地满足客户的请求.

有关不同驱动程序和帮助的更多信息,请访问 Laravel文档

I am sending push notifications from my server and want it to simply be executed in a background process. I've read the Laravel docs and I know about database driver and some other options as well. I've got it working with database driver on my local machine but one thing is bugging me that I've to start a background thread to listen for jobs which gets added to the queue using php artisan queue:listen --deamon.

The point is, it is always consuming some of my resources and memory by running like a 'crone' task. I only want to create a new process when I trigger the push notification and it should start execution as soon it is added and after that that process should be closed. While on the other hand with laravel jobs I always have to run a background process which I want to avoid and also I am using a shared hosting which doesn't allow me to install "supervisor" on my server to monitor my jobs execution.

Can anyone clear this ambiguity?? What will be the better way to handle this scenario?

解决方案

After some research, I've decided to go with database driver. There are some other great options as well, but the choice will depend on your system workload.

The point is, sync driver uses the main thread for execution of tasks which is useful for only when you are in development. If you have a production system then you might need to consider some other option to run your queue. The main idea of queuing long-running tasks is to be able to execute them in some background process so your main application thread won't block and you can serve your client requests more quickly.

For further information on different drivers and help please visit Laravel docs

这篇关于laravel队列-同步驱动程序如何工作?它是在单独的进程中还是在主执行线程中执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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