Skip to content
Advertisement

PHP is single-threaded , How job and queue works in laravel?

I had an interview yesterday, He asked me a question. PHP is a single-threaded language then how jobs and queues work in laravel behind the scenes?

Advertisement

Answer

Single-threaded doesn’t mean you can’t launch multiple instances of the program, it means the program cannot execute multiple parts of itself simultaneously.

With this consideration in mind, you’ll easily understand that when you are running the queue with php artisan queue:work, a new worker (a PHP process) starts and executes every new jobs pushed to the queue.

This worker runs alongside any other programs, single-threaded or not.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement