I am echoing json_encoded data from one php script to another (the request is made by fsockopen/GET).
When having encoded an array with 40 elements, there is no problem. When doing exactly the same thing with 41, some numbers and is added to the beginning of the json string.
This is the beginning of the string just before I echo it:
{"transactions":[{"transaction_id":"03U191739F337671L",
This is how I send the data:
header('Content-Type: text/plain; charset=utf-8');
error_log(json_encode($transaction_list));
echo json_encode($transaction_list);
As soon as I have received the data in the requesting script I print it again to error_log:
27fc
{"transactions":[{"transaction_id":"03U191739F337671L",
The "27fc " is not there if I retrieve less data.
This is how I handle the response:
$response="";
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
//Seperate header and content
$separator_position = strpos($response,"
");
$header_text = substr($response,0,$separator_position);
$body = substr($response,$separator_position+4);
error_log($body);
fclose($fp);
I have tried playing around with the time out of the fsockopen request, that doesn't matter. The same thing with max_execution_time and max_input_time in php.ini, doesn't matter. I was thinking that the content in some way may have been cut due to time out...
The 41st array is having no different format of the content than the preceding ones.
What is happening and how can I fix it?
I am using Linux, Apache (httpd) and PHP.
UPDATE
The data seems to be chunked. In the response, following header is included: "Transfer-Encoding: chunked".