Home > Article > Backend Development > How to set timeout in php
Solution to php setting timeout:
(1) Initial setting script execution time
Open the php.ini file and find:
max_execution_time=30
Change it to:
max_execution_time=600
If you do not have server modification permissions, you can set the timeout through the built-in PHP script method and perform long-term operations. Add the following code to the PHP file:
<?php ini_set('max_execution_time', 600);//秒为单位,自己根据需要定义
You can also set the timeout through the .htaccess file and add the following code to the file:
php_value max_execution_time 600
(2) Reset the script execution time and reset Set timer
set_time_limit ( int $seconds ) : bool seconds------最大的执行时间,单位为秒。如果设置为0(零),没有时间方面的限制。
Set the time allowed for the script to run, in seconds. If this setting is exceeded, the script returns a fatal error. The default value is 30 seconds, or the value defined in max_execution_time
in php.ini
, if this value exists.
When this function is called, set_time_limit()
will restart the timeout counter from zero. In other words, if the default timeout is 30 seconds and set_time_limit(20)
is called when the script has been running for 25 seconds, then the total time the script can run before timing out is 45 seconds.
Recommended tutorial: "php tutorial"
The above is the detailed content of How to set timeout in php. For more information, please follow other related articles on the PHP Chinese website!