dongtiao2105 2018-07-16 16:04
浏览 105

分段错误(核心转储)Laravel SwiftMailer

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.

  • 写回答

1条回答 默认 最新

  • douou6807 2018-07-26 20:00
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中