Very long json response stops and sends HTTP headers as text and then continues

I completely lost this problem.

I have an ajax request that receives a json response. The request works fine in most situations, however it seems to stumble when the json response is very large.

The problem is that the answer ends in the form:

...est":"test length"}]]}
HTTP/1.1 200 OK
Date: Wed, 21 Sep 2011 17:10:32 GMT
Server: Apache/2.2.11 (Win32) mod_ssl/2.2.11 OpenSSL/0.9.8k PHP/5.3.0
X-Powered-By: PHP/5.3.0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=90
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

5b03d
{"ResultsInfo":{"RequestID":"131661886010","FeedCompletion":{"0":"100"}},"ResultsData":[[{"test":"test length"},{"test":"test length"},

...0

... are more of the same "{" test ":" test length "}," string

Thus, the answer is presented in the form:

  • Last piece of data
  • Http response header printed in body
  • Symbols '5b03d'
  • First piece of data
  • Character '0'

THERE IS NO EXTRACT answer length that this is happening, but it’s normal on 360791 characters, but not 372797 characters.

Yii PHP, .

, - - .

?

_ ____________________________________

/json, , . Tes , , ( applciaiton/json):

HTTP/1.1 200 OK
Date: Thu, 22 Sep 2011 08:48:28 GMT
Server: Apache/2.2.11 (Win32) mod_ssl/2.2.11 OpenSSL/0.9.8k PHP/5.3.0
X-Powered-By: PHP/5.3.0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=89
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/json

script?

** 2_ ________________________________

, , , :

HTTP/1.1 200 OK
Date: Thu, 22 Sep 2011 11:55:39 GMT
Server: Apache/2.2.11 (Win32) mod_ssl/2.2.11 OpenSSL/0.9.8k PHP/5.3.0
X-Powered-By: PHP/5.3.0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 372797
Keep-Alive: timeout=5, max=90
Connection: Keep-Alive
Content-Type: application/json

, , chunked. - , , .

** , "5b03d" "0".

EDIT_3_ __________________________

, php-

$dataArray = array(
    'ResultsData'=>array(
          array('test'=>'test length'),
          array('test'=>'test length'),
          array('test'=>'test length'),
          ...
));

$return = json_encode($dataArray);

header('Content-Length: '.strlen($return)); 
header('Content-type: application/json');

echo $return;
+5
4
+2

Java, json-, , , , . json , . , .

9492 . 1495 , 5204 , Wireshark tcp. 1495 , 1298 .

. . . , Chrome.

json , , 4000 .

chunkin, . , : Javaserver html 12 . Json sendt , .

, apache, Java-.

+2

, .

php :

<?php

// Make a large array of strings
for($i=0;$i<10000;$i++)
{        
  $arr[] = "testing this string becuase it is must longer than all the rest to see if we can replicate the problem. testing this string becuase it is must longer than all the rest to see if we can replicate the problem. testing this string becuase it is must longer than all the rest to see if we can replicate the problem.";
}

// Create one large string from array
$var = implode("-",$arr);

// Set HTTP headers to ensure we are not 'chunking' response
header('Content-Length: '.strlen($var)); 
header('Content-type: text/html');

// Print response
echo $var;

?>

.

- ? ( )

+1

Chunked Json. ..

, , PHP - .

  • ob_start()... ob_end_flush() , , content-lenth .

  • . : ob_start (ob_gzhandler)... ob_end_flush() .

  • json script.

  • "". .

dataArray = array ('ResultsData' = > array (length0, length1, length2,...));

echo json_encode ($ dataArray, JSON_NUMERIC_CHECK);

JSON_NUMERIC_CHECK .

  • ? 5b03d? ?

  • I think the content length of 373KB is far from memory overflow?

0
source

All Articles