Skip to content

Commit 3c69b10

Browse files
committed
Merge branch 'refs/heads/child-process-example'
2 parents 4055169 + bf8f7ea commit 3c69b10

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

examples/child-child-bitch.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/child-child.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
require __DIR__ . '/../vendor/autoload.php';
4+
5+
$i = 0;
6+
7+
// block all the things!
8+
while (true) {
9+
echo ++$i . "\n";
10+
11+
sleep(1);
12+
}

examples/child-process.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
<?php
22

3-
require __DIR__ . '/../vendor/autoload.php';
3+
require __DIR__ . '/../vendor/autoload.php';
44

5-
$loop = React\EventLoop\Factory::create();
5+
$loop = React\EventLoop\Factory::create();
66

7-
$process = new React\ChildProcess\Process('php child-child-bitch.php');
7+
$process = new React\ChildProcess\Process('php child-child.php');
88

9-
$process->on('exit', function($exitCode, $termSignal) {
10-
echo "Child exit()\n";
11-
});
12-
13-
$loop->addTimer(0.001, function($timer) use ($process) {
14-
$process->start($timer->getLoop());
9+
$process->on('exit', function($exitCode, $termSignal) {
10+
echo "Child exit\n";
11+
});
1512

16-
$process->stdout->on('data', function($output) {
17-
echo "child bitch says what?: {$output}";
18-
});
19-
});
13+
$loop->addTimer(0.001, function($timer) use ($process) {
14+
$process->start($timer->getLoop());
2015

21-
$loop->addPeriodicTimer(5, function($timer) {
22-
echo "Parent can not be blocked by puny child!\n";
16+
$process->stdout->on('data', function($output) {
17+
echo "Child script says: {$output}";
2318
});
19+
});
2420

25-
$loop->run();
21+
$loop->addPeriodicTimer(5, function($timer) {
22+
echo "Parent cannot be blocked by child\n";
23+
});
2624

27-
echo "Parent is done\n";
25+
$loop->run();

0 commit comments

Comments
 (0)