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.