Some systems, such as Ubuntu, actually already run with separate CLI and Apache configurations in /etc/php5 .
Corresponding command in ini file:
max_execution_time = 30 ; Maximum execution time of each script, in seconds
However, if you cannot change php.ini for any reason, you can create a new php.ini with command-line-friendly configuration settings and point to the file as follows:
php -c /path/to/ini/php.ini -f script.php
Or you can use the Cailin solution and set a time limit at the top of the file, but if you are running a server with PHP safe mode turned on, you will have to use your own ini file.
Horuskol
source share