phplaravellaravel-4beanstalkdpheanstalk

laravel mail queueing - Insufficient data for unserializing


I am using

Ubuntu
laravel 4.2
beanstalked

when i try to

php artisan queue:work

it returns

 [ErrorException]                                                  
  Insufficient data for unserializing - 1403 required, 218 present  

mail function (confide package)

Mail::queueOn(
                    Config::get('confide::email_queue'),
                    Config::get('confide::email_account_confirmation'),
                    compact('user'),
                    function ($message) use ($user) {
                        $message
                            ->to($user->email, $user->username)
                            ->subject(Lang::get('confide::confide.email.account_confirmation.subject'));
                    }
                );

Solution

  • I came across this problem as well and I think I've got the solution.

    When an email gets queued, Laravel needs to serialize all of the email's data so it can be recalled later on when the queue is being processed.

    The problem is that when you try to serialize an instance of an Eloquent model ($user in this case) the serialized string will be too large to be stored in the queue.

    To get around this, store the specific values you need in an array before calling Mail::queueOn and attach that array to the closure you pass as an argument to Mail::queueOn.

    $data = array(
        'email' => $user->email,
        'username' => $user->username
    );
    
    Mail::queueOn(
        Config::get('confide::email_queue'),
        Config::get('confide::email_account_confirmation'),
        compact('user'),
        function ($message) use ($data) {
            $message
                ->to($data['email'], $data['username'])
                ->subject(Lang::get('confide::confide.email.account_confirmation.subject'));
        }
    );
    

    I found the solution while looking at this issue in GitHub