Home >Backend Development >PHP Tutorial >PHP Fatal error: Maximum execution time solution

PHP Fatal error: Maximum execution time solution

王林
王林Original
2023-06-24 21:45:041212browse

When using PHP programming, sometimes you will encounter the following error message:

“PHP Fatal error: Maximum execution time of xx seconds exceeded in filename.php on line xx”

This error message means that the PHP program was forcibly terminated because the execution time exceeded the preset maximum execution time (usually 30 seconds). Next, we will talk about how to solve this problem.

1. Modify the php.ini file

Method one is to directly modify the php.ini file. This method allows you to set the maximum execution time of PHP globally.

  1. Find the php.ini file, the general path is /etc/php.ini or /usr/local/etc/php.ini
  2. Find this line: max_execution_time = 30
  3. Change 30 to any time you need (in seconds), for example: max_execution_time = 60
  4. Save the changes, restart the Apache or nginx server, and done!

2. Use the set_time_limit() function to reset the maximum execution time

The next step is method two. By using the set_time_limit() function, you can set the maximum execution time of the current script to Make time.

  1. In the script that needs to set the maximum execution time, add the set_time_limit(xxx) function.
  2. Where xxx represents the time you want to set (in seconds), for example: set_time_limit(60)
  3. Save the modifications, re-execute the script, and done!

3. Add the following code to the php file

There is another way to add the following line of code to the php file:
ini_set('max_execution_time', '0 ');//0 means no time limit, you can set the specific running time according to your needs

In this way, you can directly set the maximum execution time of the current script in the script to any time you need.

Summary

The above is about how to solve the "Maximum execution time" error in PHP and Apache. Whether you modify php.ini, set it with the set_time_limit() function, or specify it directly in the php file, you can solve this problem. I believe they will all come in handy during your PHP programming process.

The above is the detailed content of PHP Fatal error: Maximum execution time solution. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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