Home > Backend Development > PHP Tutorial > How Can I Change PHP's Maximum Execution Time Without Editing php.ini?

How Can I Change PHP's Maximum Execution Time Without Editing php.ini?

Mary-Kate Olsen
Release: 2024-12-03 03:39:14
Original
701 people have browsed it

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)
Copy after login

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');
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template