PHP scripts are executed using the "php" command, depending on the timeout limit?

Are PHP scripts executed using the php command, depending on the timeout limit? I plan to schedule php scripts using cron.

+8
php cron crontab timeout
source share
3 answers

Yes, but you can set an unlimited timeout by adding it to the top of the script:

set_time_limit(0); 
+18
source share

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.

+11
source share

It depends. If your PHP file is a PHP CLI, the default max_execution_time is zero (this means there is no limit).

On the other hand, if it's an old-style CGI binary, the max_execution_time limit will affect you, and you will need to call set_time_limit to get rid of it (unless you are in the scary safe PHP mode).

+8
source share

All Articles