Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 685
tmw Avatar asked Apr 18 '17 08:04

tmw


People also ask

What is sync in Laravel queue?

Sync, or synchronous, is the default queue driver which runs a queued job within your existing process. With this driver enabled, you effectively have no queue as the queued job runs immediately.

What is Sync driver in Laravel?

The sync driver executes the process on the main execution thread instead of a background worker.

How does queue work in Laravel?

Laravel queues provide a unified queueing API across a variety of different queue backends, such as Amazon SQS, Redis, or even a relational database. Laravel's queue configuration options are stored in your application's config/queue. php configuration file.

How do I know if my Laravel queue is working?

Show activity on this post. This is lower level but in the same vein you could run a command such as ps -aux | grep queue to literally view the running queue processes on whatever server your application/queue workers are running on.


1 Answers

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

like image 163
tmw Avatar answered Oct 07 '22 15:10

tmw