title: How can I stop an infinite recursive function in PHP from eating all the available memory and eventually crashing the laptop?
body: <p>I have a simple infinite recursive code here:</p>
  <pre><code>&lt;?php
      function test() {
          test();
      }
  
      test();
  </code></pre>
  <p>When I try to run the same, it eats up all the memory and eventually my laptop hangs. What I am looking for is a way to catch this and stop the machine from hanging. Is there any <em>error handler</em> in PHP for the same?</p>
  <blockquote>
  <p>Things I have read and tried: setting max_execution_time to, let’s say, 5 seconds and catch the error line number. This didn’t work as proposed.</p>
  </blockquote>
  <p>Is there another way to catch and stop this?</p>
  <p>I am using <a href="https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_16.04_LTS_.28Xenial_Xerus.29" rel="nofollow noreferrer">Ubuntu 16.04.1</a> LTS (Xenial Xerus).</p>