[PHP]PHP rpc框架hprose测试
2023-02-18 15:41:52 时间
建立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!"
相关文章
- [前端]css前端样式的模块化
- [PHP] 算法-合并两个有序链表为一个有序链表的PHP实现
- [PHP]算法-最大子数组问题思路
- [PHP] 数据结构-反转链表PHP实现
- [PHP] 数据结构-单链表头插法PHP实现
- [PHP] 数据结构-从尾到头打印链表PHP实现
- [PHP] 数据结构-输出链表倒数第k个结点PHP实现
- [PHP]算法-归并排序的PHP实现
- [PHP] 数据结构-二叉树的创建PHP实现
- [PHP] 数据结构-循环链表的PHP实现
- [PHP] 数据结构-链表创建-插入-删除-查找的PHP实现
- [PHP] 算法-两个n位的二进制整数相加问题PHP实现
- [PHP] 数据结构-线性表的顺序存储结构PHP实现
- [日常] 链表-头结点和头指针的区别
- [日常] C语言中指针变量
- [日常] 算法-单链表的创建-尾插法
- [日常] 算法-单链表的创建
- [日常] 算法-旋转字符串-三步翻转法
- [日常] 算法-旋转字符串-暴力移位法
- [日常] C语言中的字符数组和字符串