processing JSON data gives PHP Notice & PHP Warning in Unknown on line 0

  fastcgi, iis, php

2019 server running IIS with FastCGI/PHP/MSSQL
I receive JSON data from external source. The script works most of the time:

$json = file_get_contents('php://input');

/* change json into array */
function decode_json($json) {
    $j = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
    return $j;
}

/* store json in a text file for logging/debugging */
function save_log($dir, $extn, $text) {
    file_put_contents($dir . time() . "." . $extn, $text);
}

$jd = decode_json($json);
$log = save_log('./Logs/', 'txt', $json);

foreach($jd['Records'] as $r){
    //extract needed data
    //save to DB
}

But in some cases I get a 500 error with this response:

PHP Notice: Unknown: file created in the system’s temporary directory in Unknown on line 0

PHP Warning: Cannot modify header information – headers already sent in Unknown on line 0

If I take JSON data saved in the log file (17KB) and split it in half and re-send each half separately it will get processed with no errors. This makes me think that there is a limit on size somewhere, but this is only 17KB of data and I could not find where the limit would come from.

In php.ini I have memory limits in MB, and windows TEMP directory is added to the open_basedir and upload_tmp_dir, and sys_get_temp_dir() reports the TEMP directory above. I am not sure how to continue troubleshooting this.

Source: Ask PHP

LEAVE A COMMENT