title: How to limit execution time of CLI PHP script
body: <p>I have an issue whereby occasionally a script that I run (which has dependencies on other websites) hangs trying to retrieve elements from these other websites if there is no response. I appreciate that I need to look at this part of the code again.</p>
  
  <p>But, in the meantime, I want to understand why these commands that I have tried and put at the top of my PHP code are not working? </p>
  
  <pre><code>ini_set('max_execution_time', 30);
  set_time_limit(30);
  </code></pre>
  
  <p>The scripts are run entirely in PHP and executed as CLI PHP (not as web pages launched from a browser) as :</p>
  
  <pre><code>php /var/www/html/client/index.php
  </code></pre>
  
  <p>The scripts execute fine, but if one of them hangs, it gets stuck as a process (as viewed via <code>TOP</code> or <code>HTOP</code>) and uses resources while it tries to execute and never closes.</p>
  
  <p>Is there any other way to force the scripts to stop and close other than what I have already tried?</p>
  
  <p>Thank you.</p>