沃梦达 / 编程问答 / php问题 / 正文

Laravel 5.3 电子邮件队列中不允许序列化“关闭"

Serialization of #39;Closure#39; is not allowed in Laravel 5.3 Email Queue(Laravel 5.3 电子邮件队列中不允许序列化“关闭)

本文介绍了Laravel 5.3 电子邮件队列中不允许序列化“关闭"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿意使用 queue 向电子邮件地址列表发送电子邮件.不使用队列我的代码工作正常,但使用队列它显示以下错误:

I am willing to send email to list of email address using queue. Without using queue my code is working fine but with queue it's showing following error:

Exception in Queue.php line 86: Serialization of 'Closure' is not allowed

    in /home/hizbul/Development/Projects/Laravel/fastskool/vendor/laravel/framework/src/Illuminate/Queue/Queue.php line 86
    at serialize(object(SendMessageToStudent)) in Queue.php line 86
    at Queue->createPayload(object(SendMessageToStudent), '') in DatabaseQueue.php line 81
    at DatabaseQueue->push(object(SendMessageToStudent)) in Dispatcher.php line 184
    at Dispatcher->pushCommandToQueue(object(DatabaseQueue), object(SendMessageToStudent)) in Dispatcher.php line 159
    at Dispatcher->dispatchToQueue(object(SendMessageToStudent)) in Dispatcher.php line 73
    at Dispatcher->dispatch(object(SendMessageToStudent)) in DispatchesJobs.php line 17
    at Controller->dispatch(object(SendMessageToStudent)) in MessageController.php line 49
    at MessageController->store(object(Request))
    at call_user_func_array(array(object(MessageController), 'store'), array(object(Request))) in Controller.php line 55
    at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 44
    at ControllerDispatcher->dispatch(object(Route), object(MessageController), 'store') in Route.php line 189
    at Route->runController() in Route.php line 144
    at Route->run(object(Request)) in Router.php line 653
    at Router->IlluminateRouting{closure}(object(Request)) in Pipeline.php line 53
    at Pipeline->IlluminateRouting{closure}(object(Request)) in StaffAndAdmin.php line 40
    at StaffAndAdmin->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in ModuleManager.php line 29
    at ModuleManager->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in SwitchDatabaseConnection.php line 36
    at SwitchDatabaseConnection->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in SubstituteBindings.php line 41
    at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in VerifyCsrfToken.php line 65
    at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in ShareErrorsFromSession.php line 49
    at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in StartSession.php line 64
    at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
    at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in EncryptCookies.php line 59
    at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in Pipeline.php line 104
    at Pipeline->then(object(Closure)) in Router.php line 655
    at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 629
    at Router->dispatchToRoute(object(Request)) in Router.php line 607
    at Router->dispatch(object(Request)) in Kernel.php line 268
    at Kernel->IlluminateFoundationHttp{closure}(object(Request)) in Pipeline.php line 53
    at Pipeline->IlluminateRouting{closure}(object(Request)) in Debugbar.php line 51
    at Debugbar->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
    at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
    at Pipeline->IlluminatePipeline{closure}(object(Request)) in Pipeline.php line 33
    at Pipeline->IlluminateRouting{closure}(object(Request)) in Pipeline.php line 104
    at Pipeline->then(object(Closure)) in Kernel.php line 150
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
    at Kernel->handle(object(Request)) in index.php line 68

我正在使用 database 作为队列驱动程序.

I am using database as queue driver.

以下是我的队列作业处理程序代码:

Following is my Queue job handler code:

    class SendMessageToStudent implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    private $data;

    /**
     * Create a new job instance.
     *
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        $this->data = $request;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $student = $this->data;
        $arrStudent = (new Message())->getEmailAddressList($student);
        Mail::to($arrStudent)->send(new MessageSent($student));
    }
}

和调度员代码:

$this->dispatch(new SendMessageToStudent($request));

我期待一个可行的解决方案.

I am expecting a feasible solution.

推荐答案

你不能序列化请求.只有 eloquent 模型可以序列化和反序列化.见这里:https://laravel.com/docs/5.2/queues#writing-工作类

You cannot serialize request. Only eloquent model can be serialized and unserialzed. See here: https://laravel.com/docs/5.2/queues#writing-job-classes

你应该使用 $request->all() 而不是 $request.由于 Request 被视为关闭.

You should use $request->all() instead of $request. Since Request is treated as closure.

这篇关于Laravel 5.3 电子邮件队列中不允许序列化“关闭"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Laravel 5.3 电子邮件队列中不允许序列化“关闭"

基础教程推荐