更新 - 这已缩小到 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
我已经尝试过 beanstalkd 和数据库驱动程序,没有变化。为简单起见,我使用以下命令:
<?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();
}
}