Example #1
0
<?php

use EventLoop\EventLoop;
use Rxnet\Operator\RetryWithDelay;
require __DIR__ . "/../../vendor/autoload.php";
$loop = EventLoop::getLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$http = new \Rxnet\Http\Http();
// Simple query
$http->get("http://www.perdu.com")->subscribeCallback(function (\GuzzleHttp\Psr7\Response $response) {
    echo "\nLost :\n" . html_entity_decode($response->getBody()) . "\n";
});
// Handling errors
$http->get("http://www.thisdomaindoesnotexistforreal.com")->doOnError(function (\Exception $e) {
    printf("[%s]Can't find this domain : %s\n", date('H:i:s'), $e->getMessage());
})->retryWhen(new RetryWithDelay(4, 1000))->subscribeCallback(null, function (\Exception $e) {
    printf("[%s]Definitly can't find this domain : %s\n", date('H:i:s'), $e->getMessage());
}, null, $scheduler);
Example #2
0
<?php

use EventLoop\EventLoop;
use Rxnet\Operator\RetryWithDelay;
require __DIR__ . "/../../vendor/autoload.php";
$loop = EventLoop::getLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$http = new \Rxnet\Http\Http();
// Simple query
$http->get("http://online-1.4x.fr:4001/v2/keys/registry?recursive=true")->subscribeCallback(function (\GuzzleHttp\Psr7\Response $response) {
    var_dump((string) $response->getBody());
});
Example #3
0
<?php

use EventLoop\EventLoop;
use Rxnet\Operator\RetryWithDelay;
require __DIR__ . "/../../vendor/autoload.php";
$loop = EventLoop::getLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$http = new \Rxnet\Http\Http();
// Or multi
$words = ['reactiveX', 'php', 'yolo'];
\Rx\Observable::interval(100)->takeWhile(function () use(&$words) {
    return $words;
})->map(function () use(&$words) {
    return array_shift($words);
})->subscribeCallback(function ($word) use($http, $scheduler) {
    echo "Query for {$word}\n";
    $http->get("https://www.google.com/search?q={$word}")->timeout(1000)->retry(3)->subscribeCallback(function () use($word) {
        echo "Get search response for {$word} \n";
    }, function (\Exception $e) use($word) {
        echo "Get and error for {$word} : {$e->getMessage()} \n";
    }, null, $scheduler);
}, null, null, $scheduler);
Example #4
0
<?php

use EventLoop\EventLoop;
use Rxnet\Operator\RetryWithDelay;
require __DIR__ . "/../../vendor/autoload.php";
$loop = EventLoop::getLoop();
$scheduler = new \Rx\Scheduler\EventLoopScheduler($loop);
$http = new \Rxnet\Http\Http();
// Simple query
$http->get("http://127.0.0.1:8080/articles/233/test", ['stream' => true])->subscribeCallback(function (\GuzzleHttp\Psr7\Response $response) {
    echo ".";
});
$loop->run();