<?php require __DIR__ . '/../vendor/autoload.php'; // data can be given as first argument or defaults to "y" $data = (isset($argv[1]) ? $argv[1] : 'y') . "\n"; // repeat data X times in order to fill around 200 KB $data = str_repeat($data, round(200000 / strlen($data))); $loop = React\EventLoop\Factory::create(); if (!defined('STDOUT') || stream_set_blocking(STDOUT, false) !== true) { fwrite(STDERR, 'ERROR: Unable to set STDOUT non-blocking (not CLI or Windows?)' . PHP_EOL); exit(1); } // write data to STDOUT whenever its write buffer accepts data // for illustrations purpose only, should use react/stream instead $loop->addWriteStream(STDOUT, function ($stdout) use ($loop, &$data) { // try to write data $r = fwrite($stdout, $data); // nothing could be written despite being writable => closed if ($r === 0) { $loop->removeWriteStream($stdout); fclose($stdout); stream_set_blocking($stdout, true); fwrite(STDERR, 'Stopped because STDOUT closed' . PHP_EOL); return; } // implement a very simple ring buffer, unless everything has been written at once: // everything written in this iteration will be appended for next iteration if (isset($data[$r])) { $data = substr($data, $r) . substr($data, 0, $r); } }); $loop->run();
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
01-timers.php | File | 239 B | 0644 |
|
02-periodic.php | File | 315 B | 0644 |
|
03-ticks.php | File | 222 B | 0644 |
|
04-signals.php | File | 504 B | 0644 |
|
11-consume-stdin.php | File | 787 B | 0644 |
|
12-generate-yes.php | File | 1.3 KB | 0644 |
|
13-http-client-blocking.php | File | 822 B | 0644 |
|
14-http-client-async.php | File | 1.76 KB | 0644 |
|
21-http-server.php | File | 1.04 KB | 0644 |
|
91-benchmark-ticks.php | File | 250 B | 0644 |
|
92-benchmark-timers.php | File | 251 B | 0644 |
|
93-benchmark-ticks-delay.php | File | 396 B | 0644 |
|
94-benchmark-timers-delay.php | File | 396 B | 0644 |
|
95-benchmark-memory.php | File | 1.85 KB | 0644 |
|