|
15 | 15 | //
|
16 | 16 | // $ dd if=/dev/zero bs=1M count=1k status=progress | gzip > /dev/null
|
17 | 17 |
|
| 18 | +use React\EventLoop\Loop; |
| 19 | + |
18 | 20 | require __DIR__ . '/../vendor/autoload.php';
|
19 | 21 |
|
20 | 22 | if (DIRECTORY_SEPARATOR === '\\') {
|
|
26 | 28 | echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL;
|
27 | 29 | }
|
28 | 30 |
|
29 |
| -$loop = React\EventLoop\Factory::create(); |
30 |
| - |
31 | 31 | // read 1 MiB * 1 Ki times
|
32 | 32 | $count = 0;
|
33 |
| -$stream = new React\Stream\ReadableResourceStream(fopen('/dev/zero', 'r'), $loop, 1024*1024); |
| 33 | +$stream = new React\Stream\ReadableResourceStream(fopen('/dev/zero', 'r'), null, 1024*1024); |
34 | 34 | $stream->on('data', function () use (&$count, $stream) {
|
35 | 35 | if (++$count > 1024) {
|
36 | 36 | $stream->close();
|
|
47 | 47 | });
|
48 | 48 |
|
49 | 49 | // report progress periodically
|
50 |
| -$timer = $loop->addPeriodicTimer(0.05, function () use (&$bytes) { |
| 50 | +$timer = Loop::addPeriodicTimer(0.05, function () use (&$bytes) { |
51 | 51 | echo "\rCompressed $bytes bytes…";
|
52 | 52 | });
|
53 | 53 |
|
54 | 54 | // report results once the stream closes
|
55 | 55 | $start = microtime(true);
|
56 |
| -$stream->on('close', function () use (&$bytes, $start, $loop, $timer) { |
| 56 | +$stream->on('close', function () use (&$bytes, $start, $timer) { |
57 | 57 | $time = microtime(true) - $start;
|
58 |
| - $loop->cancelTimer($timer); |
| 58 | + Loop::cancelTimer($timer); |
59 | 59 |
|
60 | 60 | echo "\rCompressed $bytes bytes in " . round($time, 1) . 's => ' . round($bytes / $time / 1000000, 1) . ' MB/s' . PHP_EOL;
|
61 | 61 | });
|
62 |
| - |
63 |
| -$loop->run(); |
0 commit comments