title: 'safe' json_decode( ,,, ) to prevent exhausting memory
body: <p>In my app I often call an external api that returns an json string.</p>
  
  <pre><code>$url = 'api.example.com/xyz';
  $blah = json_decode( file_get_contents( $url ) );
  </code></pre>
  
  <p>But in some cases I get</p>
  
  <blockquote>
    <p>PHP Fatal error:  Allowed memory size of xxx bytes exhausted (tried to allocate 32 bytes) in ...</p>
  </blockquote>
  
  <p>I cannot control the external API, and of course I could increase the memory for php, but that has some drawbacks.</p>
  
  <p>1- Whatever size I set, could still be too little.
  2- If I set the memory size to 'infinite' then I could run the risk of killing my server.</p>
  
  <p>Ideally I would like to 'check' before I call json_decode( ... ) that the string result into a memory exhaustion.</p>
  
  <p>Is that possible?</p>