@@ -29,10 +29,8 @@ as [Streams](https://github.com/reactphp/stream).
2929## Quickstart example
3030
3131``` php
32- $loop = React\EventLoop\Factory::create();
33-
3432$process = new React\ChildProcess\Process('echo foo');
35- $process->start($loop );
33+ $process->start();
3634
3735$process->stdout->on('data', function ($chunk) {
3836 echo $chunk;
@@ -41,8 +39,6 @@ $process->stdout->on('data', function ($chunk) {
4139$process->on('exit', function($exitCode, $termSignal) {
4240 echo 'Process exited with code ' . $exitCode . PHP_EOL;
4341});
44-
45- $loop->run();
4642```
4743
4844See also the [ examples] ( examples ) .
@@ -80,7 +76,7 @@ you can use any of their events and methods as usual:
8076
8177``` php
8278$process = new Process($command);
83- $process->start($loop );
79+ $process->start();
8480
8581$process->stdout->on('data', function ($chunk) {
8682 echo $chunk;
@@ -113,7 +109,7 @@ The `Process` class allows you to pass any kind of command line string:
113109
114110``` php
115111$process = new Process('echo test');
116- $process->start($loop );
112+ $process->start();
117113```
118114
119115The command line string usually consists of a whitespace-separated list with
@@ -129,7 +125,7 @@ $bin = 'C:\\Program files (x86)\\PHP\\php.exe';
129125$file = 'C:\\Users\\me\\Desktop\\Application\\main.php';
130126
131127$process = new Process(escapeshellarg($bin) . ' ' . escapeshellarg($file));
132- $process->start($loop );
128+ $process->start();
133129```
134130
135131By default, PHP will launch processes by wrapping the given command line string
@@ -146,7 +142,7 @@ streams from the wrapping shell command like this:
146142
147143``` php
148144$process = new Process('echo run && demo || echo failed');
149- $process->start($loop );
145+ $process->start();
150146```
151147
152148> Note that [ Windows support] ( #windows-compatibility ) is limited in that it
@@ -168,7 +164,7 @@ boundary between each sub-command like this:
168164
169165``` php
170166$process = new Process('cat first && echo --- && cat second');
171- $process->start($loop );
167+ $process->start();
172168```
173169
174170As an alternative, considering launching one process at a time and listening on
@@ -177,11 +173,11 @@ This will give you an opportunity to configure the subsequent process I/O stream
177173
178174``` php
179175$first = new Process('cat first');
180- $first->start($loop );
176+ $first->start();
181177
182- $first->on('exit', function () use ($loop) {
178+ $first->on('exit', function () {
183179 $second = new Process('cat second');
184- $second->start($loop );
180+ $second->start();
185181});
186182```
187183
@@ -191,7 +187,7 @@ also applies to running the most simple single command:
191187
192188``` php
193189$process = new Process('yes');
194- $process->start($loop );
190+ $process->start();
195191```
196192
197193This will actually spawn a command hierarchy similar to this on Unix:
@@ -212,7 +208,7 @@ wrapping shell process to be replaced by our process:
212208
213209``` php
214210$process = new Process('exec yes');
215- $process->start($loop );
211+ $process->start();
216212```
217213
218214This will show a resulting command hierarchy similar to this:
@@ -244,7 +240,7 @@ arguments:
244240
245241``` php
246242$process = new Process('sleep 10');
247- $process->start($loop );
243+ $process->start();
248244
249245$process->on('exit', function ($code, $term) {
250246 if ($term === null) {
@@ -292,9 +288,9 @@ accordingly when terminating a process:
292288
293289``` php
294290$process = new Process('sleep 10');
295- $process->start($loop );
291+ $process->start();
296292
297- $loop-> addTimer(2.0, function () use ($process) {
293+ Loop:: addTimer(2.0, function () use ($process) {
298294 foreach ($process->pipes as $pipe) {
299295 $pipe->close();
300296 }
@@ -308,9 +304,9 @@ inherited process pipes as [mentioned above](#command).
308304
309305``` php
310306$process = new Process('exec sleep 10');
311- $process->start($loop );
307+ $process->start();
312308
313- $loop-> addTimer(2.0, function () use ($process) {
309+ Loop:: addTimer(2.0, function () use ($process) {
314310 $process->terminate();
315311});
316312```
@@ -321,9 +317,9 @@ For example, the following can be used to "soft-close" a `cat` process:
321317
322318``` php
323319$process = new Process('cat');
324- $process->start($loop );
320+ $process->start();
325321
326- $loop-> addTimer(2.0, function () use ($process) {
322+ Loop:: addTimer(2.0, function () use ($process) {
327323 $process->stdin->end();
328324});
329325```
@@ -366,7 +362,7 @@ $fds = array(
366362);
367363
368364$process = new Process($cmd, null, null, $fds);
369- $process->start($loop );
365+ $process->start();
370366```
371367
372368Unless your use case has special requirements that demand otherwise, you're
@@ -429,7 +425,7 @@ instead throw a `LogicException` on Windows by default:
429425``` php
430426// throws LogicException on Windows
431427$process = new Process('ping example.com');
432- $process->start($loop );
428+ $process->start();
433429```
434430
435431There are a number of alternatives and workarounds as detailed below if you want
@@ -449,7 +445,7 @@ to run a child process on Windows, each with its own set of pros and cons:
449445 ['socket']
450446 ]
451447 );
452- $process->start($loop );
448+ $process->start();
453449
454450 $process->stdout->on('data', function ($chunk) {
455451 echo $chunk;
@@ -471,7 +467,7 @@ to run a child process on Windows, each with its own set of pros and cons:
471467
472468 ```php
473469 $process = new Process('ping example.com', null, null, array());
474- $process->start($loop );
470+ $process->start();
475471
476472 $process->on('exit', function ($exitcode) {
477473 echo 'exit with ' . $exitcode . PHP_EOL;
@@ -494,7 +490,7 @@ to run a child process on Windows, each with its own set of pros and cons:
494490 $stdout = tmpfile(),
495491 array('file', 'nul', 'w')
496492 ));
497- $process->start($loop );
493+ $process->start();
498494
499495 $process->on('exit', function ($exitcode) use ($stdout) {
500496 echo 'exit with ' . $exitcode . PHP_EOL;
@@ -520,7 +516,7 @@ to run a child process on Windows, each with its own set of pros and cons:
520516 omit any actual standard I/O pipes like this:
521517
522518 ```php
523- $server = new React\Socket\Server('127.0.0.1:0', $loop );
519+ $server = new React\Socket\Server('127.0.0.1:0');
524520 $server->on('connection', function (React\Socket\ConnectionInterface $connection) {
525521 $connection->on('data', function ($chunk) {
526522 echo $chunk;
@@ -529,7 +525,7 @@ to run a child process on Windows, each with its own set of pros and cons:
529525
530526 $command = 'ping example.com | foobar ' . escapeshellarg($server->getAddress());
531527 $process = new Process($command, null, null, array());
532- $process->start($loop );
528+ $process->start();
533529
534530 $process->on('exit', function ($exitcode) use ($server) {
535531 $server->close();
@@ -560,7 +556,7 @@ to run a child process on Windows, each with its own set of pros and cons:
560556 $code = '$s=stream_socket_client($argv[1]);do{fwrite($s,$d=fread(STDIN, 8192));}while(isset($d[0]));';
561557 $command = 'ping example.com | php -r ' . escapeshellarg($code) . ' ' . escapeshellarg($server->getAddress());
562558 $process = new Process($command, null, null, array());
563- $process->start($loop );
559+ $process->start();
564560 ```
565561
566562 See also [example #23](examples/23-forward-socket.php).
@@ -580,7 +576,7 @@ particular, this means that shell built-in functions such as `echo hello` or
580576
581577```php
582578$process = new Process('cmd /c echo hello', null, null, $pipes);
583- $process->start($loop );
579+ $process->start();
584580```
585581
586582## Install
0 commit comments