<?php require_once "../vendor/autoload.php"; use Hprose\Future; use Hprose\Swoole\Client; $test = new Client("unix:/tmp/my.sock"); $var_dump = Future\wrap("var_dump"); Future\co(function () use($test) { try { var_dump((yield $test->hello("yield world1"))); var_dump((yield $test->hello("yield world2"))); var_dump((yield $test->hello("yield world3"))); var_dump((yield $test->hello("yield world4"))); var_dump((yield $test->hello("yield world5"))); var_dump((yield $test->hello("yield world6"))); } catch (\Exception $e) { echo $e; } }); $var_dump($test->hello("async world1")); $var_dump($test->hello("async world2")); $var_dump($test->hello("async world3")); $var_dump($test->hello("async world4")); $var_dump($test->hello("async world5")); $var_dump($test->hello("async world6")); $test->hello("world1")->then(function ($result) use($test) { var_dump($result); return $test->hello("world2"); })->then(function ($result) use($test) { var_dump($result); return $test->hello("world3");
<?php require_once "../vendor/autoload.php"; use Hprose\Future; use Hprose\Http\Client; Future\co(function () { $test = new Client("http://hprose.com/example/"); var_dump((yield $test->hello("hprose"))); $a = $test->sum(1, 2, 3); $b = $test->sum(4, 5, 6); $c = $test->sum(7, 8, 9); var_dump((yield $test->sum($a, $b, $c))); var_dump((yield $test->hello("world"))); });
<?php require_once "../../vendor/autoload.php"; use Hprose\Future; use Hprose\Socket\Client; Future\co(function () { $test = new Client("unix:/tmp/my.sock"); $start = microtime(true); $n = 100; $m = 100; for ($j = 0; $j < $n; $j++) { $results = array(); for ($i = 0; $i < $m; $i++) { $results[] = $test->hello("{$j}-{$i}"); } (yield Future\all($results)); } $total = microtime(true) - $start; $average = $total / $n / $m; var_dump($total); var_dump($average); });
<?php require_once "../vendor/autoload.php"; use Hprose\Future; use Hprose\Swoole\Client; Future\co(function () { $test = new Client("tcp://127.0.0.1:1314"); $test->fullDuplex = true; $start = microtime(true); $n = 100; $m = 100; for ($j = 0; $j < $n; $j++) { $results = array(); for ($i = 0; $i < $m; $i++) { $results[] = $test->hello("{$j}-{$i}"); } (yield Future\all($results)); } $total = microtime(true) - $start; $average = $total / $n / $m; var_dump($total); var_dump($average); });
<?php require_once "../vendor/autoload.php"; use Hprose\Client; use Hprose\Future; Future\co(function () { $client = Client::create('http://hprose.com/example/'); try { (yield $client->ooxx()); } catch (Exception $e) { echo $e->getMessage(); } });
<?php require_once "../vendor/autoload.php"; use Hprose\Swoole\Client; use Hprose\Future; Future\co(function () { $client = new Client("tcp://127.0.0.1:1980"); $id = (yield $client->getId()); $client->subscribe('news', $id, function ($news) { var_dump($news); }); var_dump((yield $client->hello('hprose'))); });
<?php require_once "../../vendor/autoload.php"; use Hprose\Client; use Hprose\Future; Future\co(function () { $client = Client::create('http://hprose.com/example/'); $sum = $client->sum; try { (yield $client->ooxx()); } catch (Exception $e) { try { var_dump((yield $sum(1, 2))); } catch (Exception $e) { var_dump($e); } } });
<?php require_once "../vendor/autoload.php"; use Hprose\Future; use Hprose\Http\Client; $test = new Client("http://hprose.com/example/"); Future\co(function () use($test) { for ($i = 0; $i < 5; $i++) { var_dump((yield $test->hello("1-" . $i))); } $var_dump = Future\wrap('var_dump'); for ($i = 0; $i < 5; $i++) { $var_dump($test->hello("2-" . $i)); } for ($i = 0; $i < 5; $i++) { var_dump((yield $test->hello("3-" . $i))); } });
<?php require_once "../vendor/autoload.php"; use Hprose\Future; use Hprose\Http\Client; $test = new Client("http://hprose.com/example/"); function hello($n, $test) { $result = array(); for ($i = 0; $i < 5; $i++) { $result[] = $test->hello("{$n}-{$i}"); } (yield Future\all($result)); } Future\co(function () use($test) { $result = (yield Future\co(function ($test) { $result = array(); for ($i = 0; $i < 3; $i++) { $result[] = Future\co('hello', $i, $test); } (yield Future\all($result)); }, $test)); var_dump($result); });
<?php require_once "../vendor/autoload.php"; use Hprose\Future; use Hprose\Http\Client; $test = new Client("http://hprose.com/example/"); Future\co(function () use($test) { for ($i = 0; $i < 5; $i++) { var_dump((yield $test->hello("1-" . $i))); } }); Future\co(function () use($test) { for ($i = 0; $i < 5; $i++) { var_dump((yield $test->hello("2-" . $i))); } });
<?php require_once "../vendor/autoload.php"; use Hprose\Client; use Hprose\Future; Future\co(function () { $client = Client::create('http://hprose.com/example/'); (yield $client->oo()); (yield $client->xx()); })->catchError(function ($e) { echo $e->getMessage(); });