Home >Backend Development >PHP Problem >How to set running time in php
Generally speaking, the default maximum execution time of a PHP program is 30 seconds. If your program exceeds this time limit, an error message similar to Maximum execution time of 30 seconds exceeded will appear.
There are several solutions:
First check whether you are doing something stupid, which consumes a lot of CPU resources and time. If it really requires the program to run for a long time to get the result If the result is generated, you can
1> Increase the running time in php.ini:
max_execution_time=300
2> Add the following code in the PHP file
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
3> Use .htaccess file to increase running time:
<IfModule mod_php5.c> php_value max_execution_time 300 </IfModule>
Some other common configuration references:
<IfModule mod_php5.c> php_value post_max_size 5M php_value upload_max_filesize 5M php_value memory_limit 128M php_value max_execution_time 300 php_value max_input_time 300 php_value session.gc_maxlifetime 1200 </IfModule>
If your environment is wordpress, then in config.php, add:
define('WP_MEMORY_LIMIT', '128M');
Recommended related articles and tutorials: php tutorial
The above is the detailed content of How to set running time in php. For more information, please follow other related articles on the PHP Chinese website!