Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Queuing email in Laravel 4 with sync driver

I just want to queue an email when an user registers. So I do this when the user posts the registration form:

Mail::queue('emails.activate', $data, function($message) use ($user)
{
  $message->from('[email protected]', 'Mysite.com');
  $message->to($user->email, $user->username)->subject('Welcome');
});

The queue listener is running (php artisan queue:listen) and a supervisor process make sure it will restart if stopped.

It works, the user get the email but the HTTP response when registering is very slow, exactly as I would expect it to be if I was trying to directly send the email. If I comment all the queuing code above, the HTTP response time is just fine.

I use the sync driver in queue.app:

'default' => 'sync',
'connections' => array(

    'sync' => array(
        'driver' => 'sync',
    ),
    etc...

At last, I run my own private server (Ubuntu) with postfix. Can someone help me figure out why the response is so slow while I'm queuing the email?

like image 647
JuCachalot Avatar asked Jan 10 '14 15:01

JuCachalot


1 Answers

The sync driver runs its queued jobs just before Laravel ends its execution. That is why it is called the sync driver, you will need to change it to achieve desired functionality.

like image 196
SamV Avatar answered Sep 26 '22 10:09

SamV