【问题标题】:Laravel 5 - Queued Commands throwing spl_autoload_call() errorLaravel 5 - 排队命令抛出 spl_autoload_call() 错误
【发布时间】:2015-04-03 16:00:58
【问题描述】:

更新 - 这已缩小到 beanstalkd,sync 有效

尝试在生产环境中运行排队命令时收到以下错误:

    exception 'ErrorException' with message 'unserialize(): Function spl_autoload_call() hasn't defined the class it was called for' 
in /home/forge/default/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php:74

beantalkd 和数据库驱动我都试过了,没有变化。为简单起见,我使用以下命令:

<?php namespace App\Commands;

use App\Commands\Command;

use App\User;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldBeQueued;

class TestQueueCommand extends Command implements SelfHandling, ShouldBeQueued {

    use InteractsWithQueue, SerializesModels;
    /**
     * @var User
     */
    private $user;

    /**
     * Create a new command instance.
     *
     * @param User $user
     */
    public function __construct(User $user)
    {
        //
        $this->user = $user;
    }

    /**
     * Execute the command.
     *
     * @return void
     */
    public function handle()
    {
        \Log::info("You gave me " . $this->user->fullName());
    }

}

调度代码:

get('queue-test', function()
{
    Bus::dispatch(new TestQueueCommand(User::first()));
});

这适用于我的 Homestead 环境,但在生产中失败(Digital Ocean,Forge)。我有几个 beantalkd 工人,我已经尝试重新启动他们。我也跑过php artisan queue:flush

这是发生错误的代码(来自源代码):

/**
     * Handle the queued job.
     *
     * @param  \Illuminate\Contracts\Queue\Job  $job
     * @param  array  $data
     * @return void
     */
    public function call(Job $job, array $data)
    {
        $command = $this->setJobInstanceIfNecessary(
            $job, unserialize($data['command'])
        );

        $this->dispatcher->dispatchNow($command, function($handler) use ($job)
        {
            $this->setJobInstanceIfNecessary($job, $handler);
        });

        if ( ! $job->isDeletedOrReleased())
        {
            $job->delete();
        }
    }

【问题讨论】:

  • 没人??现在的解决方案:iron.io :/

标签: laravel laravel-5 beanstalkd laravel-forge


【解决方案1】:

过去,我在反序列化时也遇到了类似的问题。问题是默认的 Beanstalk 作业大小(65,535 字节),如果要序列化的类包含许多需要保留的属性(增加序列化字符串的大小并使用超过 65K 的存储空间),它可能不够大。

为了解决这个问题,请尝试在配置文件 (/etc/default/beanstalkd) 上使用 -z 选项将大小设置为 131,072 甚至 262,144 字节:

BEANSTALKD_EXTRA="-z 262144"

之后,您应该重新启动服务。

另请注意,配置文件路径可能不同,具体取决于您使用的发行版。

由于您使用的是 Digital Ocean,您可能会发现他们的 documentation 很有用。

【讨论】:

  • 对此我有点不知所措。即使是在命令中完成的最简单的任务,例如将“Hello World”写入日志,也会以同样的方式失败。有很多属性,没有什么超级复杂的事情。
  • 但是您是否至少尝试过增加作业大小以查看它是否有效? documentation 中也有关于此类问题的注释:不要通过 use 指令使对象可用于排队的闭包,而应考虑传递主键并从队列作业中重新拉出关联的模型。这通常可以避免意外的序列化行为。
  • 啊,这很有趣。我现在正在使用 Iron,但我过去曾遇到过失控工作的问题,所以我希望将所有内容都保留在 Beantsalk 上。有时间我会四处逛逛并报告。我只是在终端中运行beanstalkd -z 26144 吗?
  • 您只需要编辑 Beanstalk 的配置文件并重新启动服务。查看我的更新回复。
猜你喜欢
  • 2015-06-30
  • 2015-05-25
  • 1970-01-01
  • 1970-01-01
  • 2016-10-28
  • 2016-12-10
  • 2017-04-06
  • 2021-07-29
  • 2022-01-24
相关资源
最近更新 更多