laravel 队列 - 同步驱动程序如何工作?它是在单独的进程中执行还是在主执行线程中执行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43467680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:48:40  来源:igfitidea点击:

laravel queues - how sync driver works? Does it executes in a seperated process or the main execution thread?

phpmultithreadinglaravelqueuejobs

提问by tahir waseer

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.

我正在从我的服务器发送推送通知,并希望它只是在后台进程中执行。我已经阅读了 Laravel 文档,我也了解数据库驱动程序和其他一些选项。我已经在我的本地机器上使用了数据库驱动程序,但有一件事困扰着我,我必须启动一个后台线程来侦听使用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.

关键是,它总是像“老太婆”任务一样运行,消耗我的一些资源和内存。我只想在触发推送通知时创建一个新进程,它应该在添加后立即开始执行,然后应该关闭该进程。另一方面,对于 Laravel 作业,我总是必须运行一个我想避免的后台进程,而且我使用的是共享主机,这不允许我在我的服务器上安装“主管”来监控我的作业执行。

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

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

回答by tahir waseer

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

经过一番研究,我决定和database司机一起去。还有一些其他不错的选择,但选择将取决于您的系统工作负载。

The point is, syncdriver 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.

关键是,sync驱动程序使用主线程来执行任务,这仅在您进行开发时才有用。如果您有一个生产系统,那么您可能需要考虑其他一些选项来运行您的队列。将长时间运行的任务排队的主要思想是能够在某些后台进程中执行它们,这样您的主应用程序线程就不会阻塞,并且您可以更快地为您的客户端请求提供服务。

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

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