[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!"

 

posted @   唯一客服系统开发笔记  阅读(1727)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2017-11-14 [编程] C语言变量和数据类型总结练习题
点击右上角即可分享
微信分享提示
1
chat with us