[PHP]PHP rpc框架hprose测试
建立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
<?php require_once "./vendor/autoload.php"; use Hprose\Socket\Server; function hello($name) { return "Hello $name!"; } $server = new Server("tcp://0.0.0.0:1314"); $server->setErrorTypes(E_ALL); $server->setDebugEnabled(); $server->addFunction('hello'); $server->start();
建立client.php
<?php require_once "./vendor/autoload.php"; use \Hprose\Future; use \Hprose\Socket\Client; $test = new Client("tcp://127.0.0.1:1314"); $test->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.php
php 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!"
十年开发经验程序员,离职全心创业中,历时三年开发出的产品《唯一客服系统》
一款基于Golang+Vue开发的在线客服系统,软件著作权编号:2021SR1462600。一套可私有化部署的网站在线客服系统,编译后的二进制文件可直接使用无需搭开发环境,下载zip解压即可,仅依赖MySQL数据库,是一个开箱即用的全渠道在线客服系统,致力于帮助广大开发者/公司快速部署整合私有化客服功能。
开源地址:唯一客服(开源学习版)
官网地址:唯一客服官网