Php ini execution time

What Is The PHP Time Limit?

The PHP Time Limit is the amount of time that your site will spend on a single operation before timing out. When an operation reaches the time limit set, then it will return a fatal error that looks like this:

Fatal error: Maximum execution time of xx seconds exceeded...

The default value for PHP time limit on most hosts for the PHP Time Limit is 30 seconds. You can increase this limit by following any of the methods mentioned below.

1. Most Recommended: Just Contact Your Host
Increasing the PHP Time Limit is complex and the process that differs from hosts to hosts. So it is always better to get it done from someone who knows it well. So just get in touch with your hosting company and they will be happy to do it for you.

2. Increasing PHP Time Limit via PHP.ini file
Many small shared hosted servers do not allow users to access the PHP.ini file. If you are granted access, you can directly increase the PHP Time limit through this file. If you wish to extend the limit to 300 seconds, you can enter the following line of code or update if it exists already:

max_execution_time = 300;

3. Alternative to editing PHP.ini through wp-config.php
This is another alternative to the PHP.ini method. Simply add / edit the following line in the wp-config.php of your WordPress

set_time_limit(300);

4. Modifying the .htaccess file
Some of you might have the .htaccess file where you can simply add / edit this line of code to increase the time limit.

max_execution 300

P.S: 300 in the above code samples mean 300 seconds. Feel free to change this to any appropriate number.

Other related errors and fixes:

  • How to fix error Max Execution Time Exceeded

How to increase or decrease the maximum execution time of a php script

By default PHP script execution time is set for 30 seconds at php.ini file. This is the time limit set for all the files to finish its execution. If the file takes more than this set time then the execution of the script will be stopped and error message will be displayed like this.
Fatal error: Maximum execution time of 30 seconds exceeded in F:\php_files\t\test.php on line 14
This maximum execution time limit is set inside the php.ini file like this.
max_execution_time = 30     ; Maximum execution time of each script, in seconds 
This value can be increased or decreased as per our requirement at php.ini file but note that in a server environment where many sites are hosted, any change in php.ini will affect all the sites hosted by the server. So this change is not possible unless you own the server and you are the only user. In a shared hosting our host may not like to change any settings of php.ini for our requirement. So there is a option to set the file execution time for the particular file at the individual file end. This adjustment of time limit has no effect if php is running in safe mode. Let us try to learn how this works.


echo ini_get('max_execution_time');
?>
We will use time stamp to find out the delay between starting and ending of a script execution. We will store the time stamp value at the starting of the script and then again we will record at the end of the script . The difference of these two values will give us idea how much time the script has taken to execute. Note that here between two values of time we will try to add some delay by using sleep() function. This sleep function takes numeric value in seconds and delay the execution for that many seconds. We can also create delay by using for loop but this is a better solution. Here is the code.

$t1=time();
sleep(20);
$t2=time();

$t_lapsed=$t2-$t1;
echo "Total time lapsed = $t_lapsed";

We have introduced a delay of 20 seconds and this will execute without any problem, now increase the sleep value to 50 seconds and on execution you will get the error message saying maximum execution time exceeded. This is because by default the maximum execution time set at php.ini is 30 seconds. Now let us change the above code by adding one line set_time_limit(60). Here is the code

set_time_limit ( 60 );
$t1=time();

sleep(50);

$t2=time();
$t_lapsed=$t2-$t1;
echo "Total time lapsed = $t_lapsed";

Now the script will execute fine without any error message. We can see the total time taken by the script.

We can set the time to unlimited value by making it to 0 value. Like this

set_time_limit (0);

Php ini execution time


Subscribe

* indicates required

Email Address *

First Name

Last Name

Subscribe to plus2net


    Php ini execution time

    plus2net.com

    Click here for More on PHP File functions

    Akshata

    07-12-2018

    After doing all the changes in php.ini file still facing same issue(getting same error maximum execution time exceeded error). KIndly help me out.

    Post your comments , suggestion , error , requirements etc here .

    Detail

    How can we increase the execution time of PHP script?

    To increase the script execution time, you can use the following snippet at the top of your script. ini_set ( 'max_execution_time' , '300' ); In the above example, it would set the max_execution_time directive to 300 seconds.

    How do I change maximum execution time?

    Set Max_Execution_Time globally in php..
    Locate and open your PHP build folder..
    Find the php.ini file and open it..
    Find the following line in the text configuration file – max_execution_time=30..
    Change the value 30 to the value of choice, Remember, this value is in seconds..
    Save & Close..

    What is Max execution time?

    Maximum execution time (max_execution_time) is a time limit on how long a PHP script can run. It is a way hosting providers can limit the use and abuse of server resources, especially for shared hosting. The actual default value depends on the hosting, but it-s usually set to 30 (i.e. 30 seconds).

    How does PHP calculate time of execution?

    Clock time can get using microtime() function. First use it before starts the script and then at the end of the script. Then using formula (End_time – Start_time).