0

Last few weeks I have been working from home for obvious reasons. We run our development environment via a stack of docker microservices for which we have a standard set of docker images and docker-compose files.

At work my stack works 100% without issue with regard to the calls for json_decode but when I am home and use the same files whenever json_decode is called the process "hangs". Putting some logging after the call is never reached.

One example of the call is

$ret[$row['an']]['sc'] = json_decode($row['channel']);

When the code reaches this it never gets out of it, no errors logged either.

To fix this I have to change the call to the following (please note this is running on PHP version 5.6.40) $ret[$row['an']]['sc'] = json_decode($row['channel'],false,512,JSON_INVALID_UTF8_IGNORE);

My home dev machine is a Windows PC (Win 10) but I also have a Linux drive which I can boot into but this experiences the same problem.

Additional info:

This is working upon an array of json strings such as

{"phones":["44123456789","44123456788","44123456787"]}                                          
{"phones":[]}

It hangs when the value been worked on is {"phones":[]} but if the json value has numbers it runs fine.

The json_decode is in fact hanging everything except when the value is NULL. If the value been decoded is null is carries on without issue.

On my work machine where everything runs without issue the data is the same oddly.

Additional info to support comments:

A var_dump of the first item that json is choking on

string(56) "{"phones":["44123456789","447838588850","447838588850"]}"

Output of the byte string for the failing item as per Gavins recommendation:

(
    [1] => 7b2270686f6e6573223a5b223434313233343536373839222c22343437383338353838383530222c22343437383338353838383530225d7d
)

I also have tried the three methods outlined in the solution at How to detect malformed utf-8 string in PHP?'%2C%20%24string)%3B and all are returning true (true = valid)

UPDATED 19/06/2020 below

Testing the simple php code below even this fails on the json_decode. Json_encode works fine

<?php
    $job[123] = [
        'id' => 123,
        'position' => [
            'title' => 'PHP Developer',
        ],
    ];
    $json = json_encode($job[123]);
    echo($json);
    $jsonStr = json_decode($json);
    print_r($jsonStr);
    ```
John Cogan
  • 1,034
  • 4
  • 16
  • 39
  • Does it hang on any kind of string it's attempting to parse or is it something about `$row['channel']`? `JSON_INVALID_UTF8_IGNORE` fixing it might indicated there's a wonky character in there somewhere. – Gavin Jun 05 '20 at 09:39
  • Hi Gavin, I've added additional info above. – John Cogan Jun 05 '20 at 10:04
  • [I cannot reproduce it](https://3v4l.org/979kv). Perhaps your data is not what you think. What does `var_dump($row['channel']);` print? – Álvaro González Jun 05 '20 at 14:50
  • @JohnCogan It's tedious but try printing out the actual bytes in the string at the point its failing, any non printable characters should be revealed and show what's really in there. [For example](https://3v4l.org/SRbTP). – Gavin Jun 06 '20 at 11:32
  • @Gavin Hi, Gavin, cheers for the reply, I have output the byte value and the one it fails on is shown in the original question. Not sure how to interpret the byte string though. – John Cogan Jun 09 '20 at 10:30
  • Very confusing. That string looks fine to me. Maybe replace the _ignore constant with JSON_INVALID_UTF8_SUBSTITUTE and looking for any characters it has replaced? – Gavin Jun 09 '20 at 11:43

0 Answers0