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

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

问题描述

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

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

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

解决方案

经过一番研究,我决定使用 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天全站免登陆