建立composer.json
{ "name": "hprose/examples", "description": "examples of hprose", "authors": [ { "name": "andot", "email": "mabingyao@gmail.com" } ], "require": { "php": ">=5.3.0", "hprose/hprose": "dev-master" } }
执行
composer install
建立server.php
setErrorTypes(E_ALL);$server->setDebugEnabled();$server->addFunction('hello');$server->start();
建立client.php
fullDuplex = true;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); } });
执行
php server.phpphp client.php
结果
string(19) "Hello yield world1!"string(19) "Hello yield world2!"string(19) "Hello yield world3!"string(19) "Hello yield world4!"string(19) "Hello yield world5!"string(19) "Hello yield world6!"