title: PHP: Long strings, json_encode, var_dump and echo
body: <p>I noticed that the application I was developing was breaking, I managed to narrow it down to this problem (I have set up a test case for it):</p>
  
  <pre><code>ini_set("display_errors", "1");
  error_reporting(E_ALL);
  
  error_log("[test] Memory limit: " . ini_get('memory_limit'));
  error_log("[test] Max Execution Time: " . ini_get('max_execution_time'));
  
  $testArray = array("abcdefghijklmnotuv..... 786998 characters later...ijklmEND");
  $json = json_encode($testArray);
  
  var_dump($json);
  // echo($json);
  
  error_log("[test] Memory: ".memory_get_usage()."B");
  </code></pre>
  
  <p>When I var_dump the variable $json, I get the correct output:</p>
  
  <pre><code>string(786998) "["abcdefghijklm....ijklmEND"]"
  </code></pre>
  
  <p>When I echo the variable $json, you can very briefly see something appear on the screen but then it disappears, the end response seems to be NULL.</p>
  
  <p>If I repeat the above with a string instead of an array the same thing happens.</p>
  
  <p>If I repeat the above with a string AND omit the json_encode step everything behaves as expected, the results of var_dump and echo are correct.</p>
  
  <p>During the entire process there are no errors output in the error log, my memory limits and max execution times are also okay:</p>
  
  <pre><code>[test] Memory limit: 256M
  [test] Max Execution Time: 30
  [test] Memory: 2134296B
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>A little information on my application:</p>
  
  <p>In a nutshell there are two servers. Server A sends a HTTP request to server B, server B processes the request and sends the response back to server A. The response is always a JSON encoded array. If one of the values of the array in the response is too long server A receives a NULL response.</p>