Home >Backend Development >PHP Tutorial >How Can I Extend PHP Script Execution Time Without Modifying php.ini?
Extending Execution Duration in PHP via Code, Not php.ini
When a PHP script's execution time exceeds the default maximum set in php.ini, it terminates prematurely. To overcome this limitation without altering php.ini, you can dynamically adjust this setting within your script.
Using the ini_set() function, you can effortlessly modify the maximum execution time. Simply call ini_set() with the 'max_execution_time' parameter followed by the desired time limit, like:
ini_set('max_execution_time', '300'); // Sets it to 5 minutes
For virtually unlimited execution time, provide a value of 0:
ini_set('max_execution_time', '0');
By placing this code snippet at the commencement of your script, you effectively prolong its execution without the need for external configuration changes. This technique offers flexibility and granular control over execution time, ensuring your scripts can run uninterrupted even for extended durations.
The above is the detailed content of How Can I Extend PHP Script Execution Time Without Modifying php.ini?. For more information, please follow other related articles on the PHP Chinese website!