简体   繁体   中英

Laravel how to get data from a job?

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:\\"\*\name\\";s:5:\\"12345\\";s:6:\\"\*\job\\";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?

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 "\" 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM