I am not able to send serialized closure in queue job.
AkshayGadekar opened this issue · comments
AkshayGadekar commented
- Serializable Closure Version: ^1.2
- Laravel Version:8.75
- PHP Version: 7.4
Description:
public function serializeRequest() {
$closure = function() {
return request();
};
return serialize(new SerializableClosure($closure));
}
$request = $this->serializeRequest();
dispatch(new ProcessRequest( $request)); //send request() in queue Job
when I send request() this way in queue Job:
I get this error:
Serialization of 'Closure' is not allowed
or
Serialization of 'PDO' is not allowed
Is there any other way I can send request() into queue job?
Dries Vints commented
I think in general serializing a serialized closure isn't allowed but checking with @nunomaduro first.
Nuno Maduro commented
We advice you to not send the full request object to the "queue". Instead, simply access the necessary data you need in your controller, and pull the data you need from the request object before queuing the job.