Wednesday, March 9, 2022

[FIXED] Set max_execution_time for specific controller in symfony2

Issue

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!


Solution

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
        // ..
    }
}


Answered By - Matteo

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.