File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,8 @@ a command in a sub-process::
24
24
use Symfony\Component\Process\Process;
25
25
26
26
$process = new Process('ls -lsa');
27
- $process->setTimeout(3600);
28
27
$process->run();
29
-
28
+
30
29
// executes after the the command finishes
31
30
if (!$process->isSuccessful()) {
32
31
throw new \RuntimeException($process->getErrorOutput());
@@ -110,4 +109,34 @@ To make your code work better on all platforms, you might want to use the
110
109
$builder = new ProcessBuilder(array('ls', '-lsa'));
111
110
$builder->getProcess()->run();
112
111
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
+
113
142
.. _Packagist : https://packagist.org/packages/symfony/process
You can’t perform that action at this time.
0 commit comments