Boost PHP Performance: Adjust Max Execution Time

 How to set max_execution_time using ini_set in Laravel PHP

Boost-PHP-Performance-Adjust-Max-Execution-Time

In this article we will learn how to set max_execution_time in code level in PHP . We don't need to increase our script execution time from php.ini ,we can simply write single line of code which will increase the script execution time for that perticular funciton or for that perticular piece of code .

There are lots of case arises where only one or two function of your code takes more time to execute and for those two methods you don't want to increase you max_execution_time globally , in such cases you can use the following line of code to give those perticular function to run for extended time .

Set max_execution_time in Local code :-

Use the following line of code inside your function and provide the time limitation as shown in the following code to give that perticular function extended time to execute .

public function Test(Request $request)
{
    ini_set('max_execution_time', 0);

    // your logical code here
}

The value of "max_execution_time" is available in seconds you can simply increase the seconds value as you want but if you want to set the max-execution time to unlimited then set the value to "0" as shown below .

Set max_execution_time Globally :-

You can also set your max_execution_time globally also for all of your projects . Just follow the below steps to increase script execution time globally in php .

  • Go-to your php.ini file
  • Search( ctrl+f ) for max_execution_time
  • Increase the time limit you want ( in seconds )
Set Max Execution Time in code - PHP

The value of max_execution_time in php.ini file is available in seconds you can simply increase the seconds value as you want but if you want tp set the max-execution time to unlimited then set the value to "-1" as shown below .

max_execution_time=-1


Previous Post Next Post

Contact Form