Solve the error that php prompts Maximum execution time of 30 seconds exceeded

a lot ofInternet marketingnovice learningWordPress website, the PHP page is blank for a long time.

Then the following error message appears:

Fatal error: Maximum execution time of 30 seconds exceeded in ......

Quite simply, it means that the PHP execution time exceeds the 30 second limit.

Chen WeiliangThis error has been encountered before, and this article summarizes this error handling method.

How to fix the error?

Basically, there are 3 ways to handle this error:

  1. Modify the php configuration file php.ini file
  2. Using the ini_set() function
  3. Using the set_time_limit() function

1) Modify the php configuration file php.ini file

Find the php.ini file and find it in this file:

max_execution_time = 30 ;

On this line, set the number 30 to the desired value (in seconds).

It can also be directly modified to:

max_execution_time = 0; //无限制

Note that a reboot is required after modificationLinuxserver.

2) Use the ini_set() function

For those who cannot modify php.ininew mediaPeople, can use the ini_set() function to change the maximum execution time limit.

Add the following code at the top of the program:

ini_set('max_execution_time','100');
  • The above setting is 100 seconds, you can also set it to 0, which means not limited to execution time.

3) Use the set_time_limit() function

At the top of the program add:

set_time_limit(100);
  • This means that the maximum execution time is set to 100 seconds.
  • Of course, the parameter can also be set to 0, which meansunlimited∞.

set_time_limit function description:

void set_time_limit ( int $seconds )

What this function does is to set the time (in seconds) that the script is allowed to run.

  • If this setting is exceeded, the script will return a fatal error.
  • The default is 30 seconds, if this value exists, it is the value defined in max_execution_time in php.ini.
  • When this function is called, set_time_limit() will restart the timeout counter from zero.

In other words, if the timeout defaults to 30 seconds, and when the script runs for 25 seconds, callset_time_limit(20), the script can run for a total of 45 seconds before timing out.

This doesn't work when php is running in safe mode.

Safe Mode can be turned off:

  • Onphp.iniSet safe_mode to off in .
  • or changephp.initime limit in .

set_time_limit Examples

If Safe Mode is not turned on, the installer will run for 25 seconds.

For example:

<?php
if(!ini_get('safe_mode')){
set_time_limit(25);
}

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "Solving the Error of Maximum Execution Time of 30 seconds exceeded in PHP", which is helpful to you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-1481.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top