Reputation: 1234
I got the Laravel queue (with Redis). I need to get the job from this queue. I 'm trying to do:
$queues = Queue::getRedis()->zrange('queues:confluence:delayed' ,0, -1);
foreach ($queues as $job) {
$tmpdata = json_decode($job);
$command = $tmpdata->data->command;
}
But in $command
I got this string:
"O:16:\"App\Jobs\TestJob\":8:{ s:7:\"\u0000*\u0000name\";s:5:\"12345\";s:6:\"\u0000*\u0000job\";N;s:10:\"connection\";N;s:5:\"queue\";s:10:\"confluence\";s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";i:5;s:7:\"chained\";a:0:{} }"
> It does not seems like json or anything else (what I can parse to
> normal object/array). How can I get job data in this way?
Upvotes: 2
Views: 3456
Reputation:
It seems I had same problem here: Laravel 8 problem to unserialize command from payload (of failed job)
$command = unserialize($tmpdata->data->command); will not work because we have null in serialized string "\u0000" I used:
$str = str_replace('\u0000', ' ', $payload['data']['command']);
After this string fix I use:
$unserialized = unserialize($str, ['allowed_classes' => false]);
But this seems awful solution. It must be Laravel have something better to offer.
Upvotes: 3
Reputation: 4728
The data you're seeing is serialized. You can unserialize it as such:
$command = unserialize($tmpdata->data->command);
Though take care, and read the documentation for this command as it is a potential security risk: https://www.php.net/manual/en/function.unserialize.php
Upvotes: 1