Archives


Master Symfony2 fundamentals

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Discover the SensioLabs Support

Access to the SensioLabs Competency Center for an exclusive and tailor-made support on Symfony
sensiolabs.com

Fabien Potencier
New in Symfony 2.4: Limit a Process Run with an idle Timeout
by Fabien Potencier – August 30, 2013 – 2 comments

Contributed by
Johannes Schmitt
in #8651.

Since the release of Symfony 2.3, the stability of the Process component has been greatly improved thanks to the hard work of Romain Neutron. But today, I want to talk about a new feature that can be quite useful when dealing with long running processes, the ability to define an idle timeout.

Up until now, you were able to limit the time a process take to finish by calling the setTimeout() method; this is a the maximum number of seconds a process can take to finish its work:

1
$process->setTimeout(2 * 3600);

In Symfony 2.4, you can also define an idle timeout (via the setIdleTimeout() method); this is the maximum number of seconds a process can run without outputting anything (on the standard or the error output):

1
$process->setIdleTimeout(10 * 60);

When a timeout occurs, the Process throws a Symfony\Component\Process\Exception\ProcessTimedOutException. You can make the difference between the two kind of timeouts by calling the isGeneralTimeout() or the isIdleTimeout() method.

Comments RSS

  • Christian Gärtner
    #1 Christian Gärtner said on the 2013/08/31 at 11:28
    Do you have to call the isGeneralTimeout() methods on the Exception? Isn' t a 100% clear in the post.
  • Marc Torres Baix
    #2 Marc Torres Baix said on the 2013/09/02 at 07:57
    @Cristian, it seems so, following #issue and there you have:

    https://github.com/symfony/symfony/pull/8651/files

    Cheers.