Php 无法序列化或取消序列化laravel中的PDO实例

Php 无法序列化或取消序列化laravel中的PDO实例,php,laravel,events,serialization,queue,Php,Laravel,Events,Serialization,Queue,我使用默认的laravel事件系统,如下所示 use \Illuminate\Database\Connection; class ExampleService { private $connection; public function __construct(Connection $connection) { $this->connection = $connection; } } class ExampleEvent { pr

我使用默认的laravel事件系统,如下所示

use \Illuminate\Database\Connection;

class ExampleService {

private $connection;

    public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }
}

class ExampleEvent {

    private $service;

    public function __construc(ExampleService $service) {
        $this->service = $service;
    }
}


class ExampleListener implements ShouldQueue {

    public function handle(ExampleEvent $event) {

    }
}

这是我的自定义服务,在这里我使用连接而不是雄辩,每当我将服务从事件解析到侦听器并将其放在队列上时,我会得到错误
,您无法序列化或取消序列化PDO实例。我希望我的侦听器使用
implements shouldqueue
,而不是创建不同的作业,并从同一个侦听器进行调度

将项目添加到队列会序列化它们

连接包含一个PDO实例,但您不能序列化一个PDO实例,因此,您会得到该错误

您应该实现这些方法以确保序列化正确进行,例如:

class ExampleService {

    private $connection;

    public function __construct(Connection $connection)
    {
        $this->connection = $connection;

    }

    public function __sleep() {
         return []; //Pass the names of the variables that should be serialised here
    }
    public function __wakeup() {
         //Since we can't serialize the connection we need to re-open it when we unserialise
         $this->connection = app()->make(Connection::class); 
    }
}

你的问题是什么?@JonStirling抱歉我有点激动,忘了放上下文谢谢你不我现在可以玩这个问题只需要正确管理我的依赖关系