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

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

问题描述

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

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.

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

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?

推荐答案

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

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.

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

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.

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

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

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

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