我得到了Laravel队列(与Redis一起)。我需要从此队列中获得工作。我正在尝试做:
$queues = Queue::getRedis()->zrange('queues:confluence:delayed' ,0, -1);
foreach ($queues as $job) {
$tmpdata = json_decode($job);
$command = $tmpdata->data->command;
}
但是在$command
中,我得到了以下字符串:
“ 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:{}}” < / p>
> 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?
答案 0 :(得分:1)
我似乎在这里遇到了同样的问题:Laravel 8 problem to unserialize command from payload (of failed job)
$command = 反序列化($tmpdata->data->command);将不起作用,因为我使用的序列化字符串“\u0000”中有空值:
$str = str_replace('\u0000', ' ', $payload['data']['command']);
在此字符串修复后我使用:
$unserialized = unserialize($str, ['allowed_classes' => false]);
但这看起来很糟糕的解决方案。一定是 Laravel 提供了更好的东西。
答案 1 :(得分:0)
您看到的数据已序列化。您可以这样反序列化它:
$command = unserialize($tmpdata->data->command);
请注意,请仔细阅读此命令的文档,因为它存在潜在的安全风险:https://www.php.net/manual/en/function.unserialize.php