Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set max_execution_time for specific controller in symfony2

Tags:

php

symfony

Using ini_set(), I can expand the maximum execution time of a script. In Symfony2, I can add ini_set to web/app.php and web/app_dev.php to apply the increased execution time to all controllers.

But in this case, I only want to expand the maximum execution time for one specific controller action in Symfony2. I'd rather not give other actions the possibility to run for a longer time than necessary.

I tried adding the ini_set at the top of the action function in the controller, but that doesn't seem to work. Any solutions? Thanks!

like image 954
dirk Avatar asked Mar 01 '16 10:03

dirk


People also ask

What should max_execution_time be?

Using PHP max_execution_time directive By default, the maximum execution time for PHP scripts is set to 30 seconds. If a script runs for longer than 30 seconds, PHP stops the script and reports an error.

What is max_execution_time in PHP INI?

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 .

What is the default execution time set in set_time_limit () in PHP?

The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php. ini . When called, set_time_limit() restarts the timeout counter from zero.


1 Answers

You can disable the PHP timeout limit with the set_time_limit function. More info here

as Example:

class TaskController extends Controller
{

    public function longTaskAction()
    {
        set_time_limit(0); // 0 = no limits
        // ..
    }
}
like image 57
Matteo Avatar answered Oct 21 '22 16:10

Matteo