Skip to content

Commit 33ffa80

Browse files
fabpotweaverryan
authored andcommitted
added docs for the process timeout feature
1 parent c1c4424 commit 33ffa80

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

components/process.rst

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ a command in a sub-process::
2424
use Symfony\Component\Process\Process;
2525

2626
$process = new Process('ls -lsa');
27-
$process->setTimeout(3600);
2827
$process->run();
29-
28+
3029
// executes after the the command finishes
3130
if (!$process->isSuccessful()) {
3231
throw new \RuntimeException($process->getErrorOutput());
@@ -110,4 +109,34 @@ To make your code work better on all platforms, you might want to use the
110109
$builder = new ProcessBuilder(array('ls', '-lsa'));
111110
$builder->getProcess()->run();
112111

112+
Process Timeout
113+
---------------
114+
115+
You can limit the amount of time a process takes to complete by setting a
116+
timeout (in seconds)::
117+
118+
use Symfony\Component\Process\Process;
119+
120+
$process = new Process('ls -lsa');
121+
$process->setTimeout(3600);
122+
$process->run();
123+
124+
If the timeout is reached, a
125+
:class:`Symfony\\Process\\Exception\\RuntimeException` is thrown.
126+
127+
For long running commands, it is your responsibility to perform the timeout
128+
check regularly::
129+
130+
$process->setTimeout(3600);
131+
$process->start();
132+
133+
while ($condition) {
134+
// ...
135+
136+
// check if the timeout is reached
137+
$process->checkTimeout();
138+
139+
usleep(200000);
140+
}
141+
113142
.. _Packagist: https://packagist.org/packages/symfony/process

0 commit comments

Comments
 (0)