0

I'm trying to work a Laravel Job which must return a response immediately and execute itself in the background.

It was working fine but I don't know what went wrong because now it is not working (I just edited tried to send Notification to a user responsible for sending email updates to other users)!

I am using sync driver because I don't want to execute php artisan queue:work command every time I put something in the queue. Here is the code! In my .env file and config/queue.php file, I've set the driver to sync.

** I am trying to send E-mails to user which takes time **

Click here to see the code executed in UserController, App\Mail\EmailUpdate and App\Jobs\SendEmailUpdates.

At first (When it was working), I was being redirected back immediately! But after some time (I think 15 minutes), it is taking about 15-20 seconds to redirect me back! It is acting like a normal PHP code and sending E-mails to users before redirecting me back!

I tried resetting the code but it didn't work! Any help would be appreciated!

Adarsh Sojitra
  • 2,059
  • 1
  • 27
  • 50
  • Because `sync` driver doesn't work using a background process. – The Alpha Feb 18 '18 at 17:45
  • So, How do you dispatch jobs with `database` driver without executing `php artisan queue:work`. And if `sync` driver doesn't work using a background process, why is it included as driver. – Adarsh Sojitra Feb 18 '18 at 17:51
  • 1
    Actually, `sync` is available for testing on local development and on a production server you should use `queue:work --daemon` to run it as a daemon, newer version of laravel applies `queue:work` as daemon by default. – The Alpha Feb 18 '18 at 17:57
  • [Also check this answer](https://stackoverflow.com/questions/26048698/what-is-the-difference-between-queuework-daemon-and-queuelisten) and read about `supervisor` on laravel queue manual. – The Alpha Feb 18 '18 at 17:58
  • @TheAlpha, I checked that answer. but `queue:work --daemon` never stops the execution. What if I close terminal? It looks really really bad! – Adarsh Sojitra Feb 18 '18 at 18:03
  • 1
    That's why you need to use a background process manager like [supervisor](https://laravel.com/docs/5.6/queues#supervisor-configuration) on the production. – The Alpha Feb 18 '18 at 18:05
  • I mean, It was working! with `sync`, It was returning be back in 1 second! and then It was executing rest of the code in the background! It was working smoothly! But now it's not! Are you sure `sync` does not run in background? – Adarsh Sojitra Feb 18 '18 at 18:07
  • Okay, I got it! – Adarsh Sojitra Feb 18 '18 at 18:18

0 Answers0