Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase laravel controller method execution time?

I want to increase execution time of my controller method to 5 minutes . I searched but many times I found just one working idea that is increase the execution time in php.ini file but I do not want this I want to increase the execution time in laravel controller for one method only. Can any one tell me how I do that??? I tried many code one example is given below

public function postGetEvents1(){

    set_time_limit(600);

    //other code

}

like image 858
Bilal Hussain Avatar asked May 29 '16 11:05

Bilal Hussain


People also ask

How do I fix max execution time of 60 seconds exceeded in laravel?

Increase the execution time at php. ini level, max_execution_time=300. Use PHP at runtime to increase it, ini_set('max_execution_time', 300); //300 seconds = 5 minutes.

What is max_execution_time in PHP?

max_execution_time int. This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30 . When running PHP from the command line the default setting is 0 .


1 Answers

This should work for you, if you want to set higher execution time limit for just one method:

public function postGetEvents1(){

    // Get default limit
    $normalTimeLimit = ini_get('max_execution_time');

    // Set new limit
    ini_set('max_execution_time', 600); 

    //other code

    // Restore default limit
    ini_set('max_execution_time', $normalTimeLimit); 

    return;
}
like image 53
Alexey Mezenin Avatar answered Sep 22 '22 00:09

Alexey Mezenin