When working with PHP scripts, let's learn what the maximum execution time setting is — and how to override the php.ini timeout value that is set with the max_execution_time variable in the php.ini settings file.
By default, the maximum execution time setting is derived from the max_execution_time variable within the php.ini timeout set of definitions, which are found in the php.ini file. But you can change the maximum allowed execution time for your individual PHP scripts. This article will show you how.
What is the PHP limit time?
One important control involved with PHP scripts is that they will have a maximum amount of time set that they can take to execute. The time limit (as known as the php.ini timeout) varies depending on the hosting company and how the maximum execution time variable has been configured globally for all PHP scripts — or individually per PHP script.
How do I fix a PHP timeout?
You can fix a PHP timeout by following the guidance in this article. You can work our Nexcess support staff to increase your php,ini timeout or example. Also, there are user.ini file settings that can be used — per directory on in the webroot.
Increasing the timeout in php.ini or user.ini file by adding a line that increases the maximum execution time is a standard method. However, you can also increase the timeout in your script itself my taking the appropriate steps documented in this article.
How to set maximum execution time
Overriding the default php.ini timeout values with your own PHP script's execution time limit is often useful and necessary step for a website admin to take. We need to learn how to set the maximum execution time using your individual PHP script's execution time limit — overriding the php.ini timeout set with the max_execution_time variable.
PHP scripts: maximum execution time definition
Maximum execution time refers to the default maximum amount of time a PHP script will run before PHP terminates the script and reports an error.
PHP scripts: how to change maximum execution time
You may use one of three possible methods to alter your maximum execution time. Those three methods are described below.
Method #1: Modify the php.ini file (via the php.ini timeout settings)
We do not permit our clients with managed hosting plans to modify their php.ini files or the php.ini timeout settings in them, but our support team may implement changes on your behalf.
Method #2: Set maximum execution time for individual PHP scripts (by overriding the default php.ini timeout settings)
You may adjust maximum execution time via PHP’s set_time_limit function. This value replaces the max_execution_time variable within the php.ini file.
For example, to change the execution time limit for a particular PHP script to ten minutes, convert the time limit to seconds add the following line at the beginning of the script:
Method #3: Set maximum execution time for PHP scripts from the CLI (by overriding the default php.ini timeout settings)
You may set the maximum execution time manually from the command line interface (CLI) by using the -d flag with the PHP command as follows:
php -d max_execution_time=300 script.php
The above command would run script.php with a maximum execution time of 300 seconds regardless of the globally set max_execution_time value.
We hope that after reading this article you learned more about the maximum execution time setting with regard to PHP scripts and how to override the php.ini timeout value that is set with the max_execution_time variable in the php.ini setting file. You can change the maximum allowed execution time for your PHP scripts as this article outlined.
If you need this change made globally, contact our support team by email at firstname.lastname@example.org for assistance.