How to avoid time limits in PHP scripts

In PHP 4 all PHP scripts had a time limit that was set in the php.ini file. The default value was 30 seconds, though every professional web design shop I know of set that value much higher, to 180 or even 300 seconds.

In PHP 5, there are two separate contexts for calling PHP: the web, and the command line. PHP on the web, a module of Apache, still has the time limits like PHP 4. PHP for the command line (cli) has no time limits

Normally PHP code is sequential: first one thing happens, then another, then another after that. If a function calls another function, execution in the first function stops till the other function has returned.

On the  web you will sometimes need the equivalent of asynchronous PHP. For instance, if the user triggers some major maintence operation, which should really play out in the background, without holding up the script that the current user is currently interacting with. On PHP.net, there was a suggestion for acheiving asynchronous PHP. This relies on CURL to make multiple calls to an URL, triggering whatever PHP script you want to trigger.

Now I’m wondering how I might achieve something similar away from the web, in the context of the command line.

Leave a Reply