PHP code example of rx / swoole

1. Go to this page and download the library: Download rx/swoole 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/ */

    

rx / swoole example snippets


  \Rx\Observable::interval(1000)
    ->take(5)
    ->subscribe(function($i){
      echo $i, PHP_EOL;
    });
    


// this example uses the rx/operator-extras package for `cut`

$file = \Rx\Swoole\Async::read(__DIR__ . '/url_list.txt');

$urlInfo = $file
    ->cut("\n")
    ->flatMap(function ($url) {
        return \Rx\Swoole\Http::get($url)
            ->map(function ($content) use ($url) {
                return $url . " is " . strlen($content) . " bytes.\n";
            });
    });

$urlInfo->subscribe(function ($info) {
        echo $info;
    });