I'm having problem when using SwiftMailer Laravel 5.2. I have a controller for sending email and I set it to run every minute. When I execute my script below with php artisan schedule:run, its keeps return an error message 'Segmentation fault (core dumped)'.
My script:
public static function sendMailCoc()
{
$mail_log = MailLog::where('status', '!=', 'SENT')->where('type', '3')->orderBy('id', 'asc')->get();
foreach($mail_log as $mail){
if($mail->to!='') {
$coc = json_decode($mail->parameter, true);
try {
Mail::queue($mail->file_view,
['to' => $mail->to_name,
'coc' => $coc,
'notif_id' => $mail->notification_id
],
function ($message) use ($mail) {
$message->to($mail->to)
->subject($mail->subject);
});
$mail->status = 'SENT';
$mail->error_message = '';
$mail->save();
}
catch(Swift_TransportException $e){
$mail->status = 'ERROR';
$mail->error_message = $e->getMessage();
$mail->save();
continue;
}catch (Exception $e) {
$mail->status = 'ERROR';
$mail->error_message = $e->getMessage();
$mail->save();
continue;
}
}
}
}
Sometimes if I test to send just one email, it works and not return an error message. But when I try to send a lot of email with looping, its always get an error message "Segmentation fault (core dumped)". I'm using Ubuntu Server 14.04.
I don't know what is causing this error. It is my script that causing this problem, Laravel, or Ubuntu Linux?
Is there any way to solve this problem? What should I check first?
Thank you for your help and answer.
Wild shot, but I've been debugging the same error message in relation to queued jobs recently:
As per Laravel 5.6 documentation (https://laravel.com/docs/5.6/queues#creating-jobs):
"Binary data, such as raw image contents, should be passed through the base64_encode function before being passed to a queued job. Otherwise, the job may not properly serialize to JSON when being placed on the queue."
My problem was resolved (almost!) as soon as I added base64_encode($input)
in constructor and base64_decode($this->input)
in handle() function.
PS: Since I was using two distributed apps for input and working on the queue, I also had to run composer dump-autoload
and php artisan cache:clear
on both apps, while also restarting the supervisor
worker, after making the code change.