-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy path12-benchmark-write.php
42 lines (34 loc) · 1.11 KB
/
12-benchmark-write.php
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
33
34
35
36
37
38
39
40
41
42
<?php
use React\ChildProcess\Process;
require __DIR__ . '/../vendor/autoload.php';
if (DIRECTORY_SEPARATOR === '\\') {
exit('Process pipes not supported on Windows' . PHP_EOL);
}
$info = new React\Stream\WritableResourceStream(STDERR);
$info->write('Pipes data to process STDIN' . PHP_EOL);
if (extension_loaded('xdebug')) {
$info->write('NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL);
}
$process = new Process('dd of=/dev/zero');
$process->start();
// 10000 * 100 KB => 1 GB
$i = 10000;
$chunk = str_repeat("\0", 100 * 1000);
$write = function () use ($chunk, $process, &$i, &$write) {
do {
--$i;
$continue = $process->stdin->write($chunk);
} while ($i && $continue);
if ($i > 0) {
// buffer full => wait for drain to continue
$process->stdin->once('drain', $write);
} else {
$process->stdin->end();
}
};
$write();
// report any other output/errors
$process->stdout->on('data', 'printf');
$process->stdout->on('error', 'printf');
$process->stderr->on('data', 'printf');
$process->stdout->on('error', 'printf');