【问题标题】:Laravel Command Queue exceptionLaravel 命令队列异常
【发布时间】:2015-03-13 12:39:08
【问题描述】:

我正在尝试实现一个 Laravel 5 队列,它将新的事件邮件发送到邮件列表。我发现您可以为此使用命令,但每次尝试执行此命令时都会出现错误异常(见下文)。我写的邮件类如下

<?php namespace App\Commands;

use Illuminate\Support\Facades\App;
use \App\Event;
use Illuminate\Support\Facades\Mail;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldBeQueued;

class EventMailing extends Command implements SelfHandling, ShouldBeQueued {

    use InteractsWithQueue, SerializesModels;

    /**
     * Create a new command instance.
     *
     * @return void
     */

    public $event;
    public $recipients;

    public function __construct(Event $event, $recipients)
    {
        $this->event=$event;
        $this->recipients=$recipients;
    }

    /**
     * Execute the command.
     *
     * @return void
     */
    public function handle(EventMailing $command, User $user)
    {
        $event = $command->event;

        print_r($event);

       /* foreach ($this->recipients as $recipient) {
            Mail::send('emails.event', $event,
                function($message) use ($event,$recipient)
                {
                    $message->from('info@gsebelux.org', 'GSE BeLux');
                    $message->subject('New event: '.$event->name);
                    $message->to($recipient);
                }
            );
        }*/
    }

}

注意:我将邮件部分注释掉以检查是否不是该部分出现故障。

我从控制器调用 EventMailing 命令,如下所示:

public function sendMail($event,$array)
{
    Queue::push(new EventMailing($event,$array));
} 

当我触发此功能并执行 php artisan queue:work --verbose 我明白了。谁能帮我解决这个问题?

  [ErrorException]                                                                        
  unserialize(): Function spl_autoload_call() hasn't defined the class it was called for  



Exception trace:
 () at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:36
 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at n/a:n/a
 unserialize() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:36
 Illuminate\Queue\CallQueuedHandler->call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:126
 Illuminate\Queue\Jobs\Job->resolveAndFire() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Jobs/BeanstalkdJob.php:51
 Illuminate\Queue\Jobs\BeanstalkdJob->fire() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:207
 Illuminate\Queue\Worker->process() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:159
 Illuminate\Queue\Worker->pop() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:107
 Illuminate\Queue\Console\WorkCommand->runWorker() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:67
 Illuminate\Queue\Console\WorkCommand->fire() at n/a:n/a
 call_user_func_array() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/Container.php:523
 Illuminate\Container\Container->call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php:115
 Illuminate\Console\Command->execute() at /home/vagrant/Code/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:253
 Symfony\Component\Console\Command\Command->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php:101
 Illuminate\Console\Command->run() at /home/vagrant/Code/vendor/symfony/console/Symfony/Component/Console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/Code/vendor/symfony/console/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /home/vagrant/Code/vendor/symfony/console/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:90
 Illuminate\Foundation\Console\Kernel->handle() at /home/vagrant/Code/artisan:36

【问题讨论】:

  • 你曾经解决过这个问题吗?我正在处理同样的错误——即使是最简单的命令
  • 这种方式并没有真正解决。用旧方法做了,创建了一个队列“EventMailing”,并从控制器推送我的工作。在队列类中,我创建了一个处理邮件工作的“fire”方法。如果有更多人为此苦苦挣扎,我会在我的网站上发表博文,问我吧。

标签: php exception laravel


【解决方案1】:

改变

public function handle(EventMailing $command, User $user)
{
    $event = $command->event;

    print_r($event);

通过

public function handle(User $user)
{
    //event is in the constructor
    $event = $this->event;

    print_r($event);

【讨论】:

    猜你喜欢
    • 2015-06-30
    • 2013-10-04
    • 2015-07-13
    • 2019-10-18
    • 2015-08-09
    • 2020-11-05
    • 2016-10-07
    • 2021-08-10
    • 2021-02-01
    相关资源
    最近更新 更多