Laravel、Hyperf框架redis队列中的序列化数据进行反序列化报错解决办法

PHP  
  1. <?php
  2. //由于字符串中含有\e00这种16禁止字符,导致直接unserialize失败。
  3. $str = 'C:25:"Hyperf\AsyncQueue\Message":101:{a:2:{i:0;O:15:"App\Job\TestJob":2:{s:4:"data";a:1:{s:2:"id";i:8;}s:14:"\x00*\x00maxAttempts";i:0;}i:1;i:0;}}';
  4. //使用正则回调替换字符
  5. $res = preg_replace_callback('/\\\x[A-Z0-9]{2}/', function ($matches){
  6. return chr(hexdec(substr($matches[0], 2)));
  7. }, $str);
  8. var_dump(unserialize($res));


评论 0

发表评论

Top