-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy path01-stdio.php
More file actions
32 lines (24 loc) · 740 Bytes
/
01-stdio.php
File metadata and controls
32 lines (24 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
use React\ChildProcess\Process;
use React\EventLoop\Loop;
require __DIR__ . '/../vendor/autoload.php';
if (DIRECTORY_SEPARATOR === '\\') {
exit('Process pipes not supported on Windows' . PHP_EOL);
}
$process = new Process('cat');
$process->start();
$process->stdout->on('data', function ($chunk) {
echo $chunk;
});
$process->on('exit', function ($code) {
echo 'EXIT with code ' . $code . PHP_EOL;
});
// periodically send something to stream
$periodic = Loop::addPeriodicTimer(0.2, function () use ($process) {
$process->stdin->write('hello');
});
// stop sending after a few seconds
Loop::addTimer(2.0, function () use ($periodic, $process) {
Loop::cancelTimer($periodic);
$process->stdin->end();
});