Home >Backend Development >PHP Tutorial >How Can I Change PHP's Maximum Execution Time Without Editing php.ini?
How to Alter Maximum Execution Time in PHP Without Modifying php.ini
In PHP, the maximum execution time is typically configured in the php.ini file. However, it is possible to override this setting within your PHP script itself.
Increasing Execution Time
To increase the maximum execution time, you can use the ini_set() function. By setting the max_execution_time key to a higher value, you can extend the script's runtime:
ini_set('max_execution_time', '300'); // 300 seconds (5 minutes)
Infinite Execution Time
If you wish to allow your script to run indefinitely, you can set the maximum execution time to 0:
ini_set('max_execution_time', '0');
Usage
Place the ini_set() call at the beginning of your PHP script to ensure it takes effect before any other code is executed. This gives your script the extended runtime you need to complete its tasks.
Additional Information
Note that modifying the maximum execution time within your script only affects the current PHP process and does not permanently change the global php.ini setting. If you need to make a persistent change, you will need to adjust the php.ini file itself.
The above is the detailed content of How Can I Change PHP's Maximum Execution Time Without Editing php.ini?. For more information, please follow other related articles on the PHP Chinese website!