You already have a custom php. ini configured in your application, or you need to contact the owner who supports it. If some of the PHP scripts take longer, the server stops and throws an error:
Fatal error: Maximum execution time of..seconds exceeded in this_file.php on line ...To to avoid this situation, you can change the directive in the php.ini config file. Let’s see how we can set the script execution time in PHP. They are listed below:
- Find the directive in the file and change its value as required by the PHP script.
; Maximum execution time of each script, in seconds; http://php.net/max-execution-time; Note: This directive is hardcoded to 0 for the CLI SAPI max_execution_time = 4000
The directive’s default value changes as needed.
Note: we have to restart the web server as soon as the changes will be made to the config file. This parameter makes the configuration global for all PHP scripts. Changes made to this file in the wrong way can create problems for the web server or live projects. - Use the built-in PHP function set_time_limit (seconds), where seconds - this is the passed argument, which is the time limit in seconds. It is used when the user changes settings outside of the php.inifile. The function is called from your own PHP code. Use when disabled. Note. If the function is called at the very beginning of the program, then the value passed to the function will be limited by the script execution time. Otherwise, if the function is called in the middle of the code, the partial script is executed and then the time limit is applied to the rest of the script.
- Use a built-in PHP function where parameters are a given config parameter and value to be set.
// The program is executed in 3ms
ini_set
(
’max_execution_time’
, 180);
?>
// Installed for an unlimited period of time
ini_set
(
’max_execution_time’
, 0);
?>
- To allow the script to run permanently and ignore user interrupts, install a built-in PHP function. It defaults to False, which throws a fatal error when the client aborts the script.
ignore_user_abort();
?>
- Use the command to change settings in configuration files and Apache files.
Syntax:php_value name value
This sets the value for that particular directive as specified.php_value max_execution_time 200
- Using cPanel configuration settings to change script execution time. This can be done in your cPanel control panel and can be used to set a time limit for a PHP script.