1. Go to this page and download the library: Download reactivex/rxphp 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/ */
x\Observable;
use React\EventLoop\Factory;
use Rx\Scheduler;
$loop = Factory::create();
//You only need to set the default scheduler once
Scheduler::setDefaultFactory(function() use($loop){
return new Scheduler\EventLoopScheduler($loop);
});
Observable::interval(1000)
->take(5)
->flatMap(function ($i) {
return Observable::of($i + 1);
})
->subscribe(function ($e) {
echo $e, PHP_EOL;
});
$loop->run();