Laravel如何从工作中获取数据? [英] Laravel how to get data from a job?

查看:101
本文介绍了Laravel如何从工作中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了Laravel队列(与Redis一起).我需要从此队列中获得工作.我正在尝试做:

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;
}

但是在 $ 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:{}}"

"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?

推荐答案

似乎我在这里遇到了同样的问题:

It seems I had same problem here: Laravel 8 problem to unserialize command from payload (of failed job)

$ command =反序列化($ tmpdata-> data-> command);将不起作用,因为我们在序列化字符串"\ u0000"中没有null我用过:

$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]);

但这似乎是可怕的解决方案.一定是Laravel有更好的选择.

But this seems awful solution. It must be Laravel have something better to offer.

这篇关于Laravel如何从工作中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆