PHP code example of joopschilder / reactphp-input-stream
1. Go to this page and download the library: Download joopschilder/reactphp-input-stream library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joopschilder / reactphp-input-stream example snippets
// Say, we have an event loop...
$loop = Factory::create();
// And say, we have a non-blocking input called $input...
$input = new DemoNonBlockingInput();
// Then we can create a ReadableStream from it like so:
$stream = new ReadableNonBlockingInputStream($input, $loop);
// If your 'select()' method takes a long time to execute, or you just don't
// feel like polling the input availability that often, you can
// set a custom polling interval by supplying an instance of PollingInterval
// as the third constructor parameter:
$lowPollingStream = new ReadableNonBlockingInputStream($input, $loop, new PollingInterval(5));
// Of course, the stream emits all expected events (except end)
$stream->on('data', fn() => print('m'));
$stream->on('error', fn() => print('e'));
$stream->on('close', fn() => print('c'));
// If you know what data your input returns, you may type-hint it:
$stream->on('data', fn(Joke $joke) => print($joke . PHP_EOL));
// Add a periodic timer for demonstration purposes
$loop->addPeriodicTimer(0.2, fn() => print('.'));
// And kick 'er off.
$loop->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.