前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[PHP]PHP rpc框架hprose测试

[PHP]PHP rpc框架hprose测试

作者头像
唯一Chat
发布2019-09-10 11:22:38
2.4K0
发布2019-09-10 11:22:38
举报
文章被收录于专栏:陶士涵的菜地陶士涵的菜地

建立composer.json

代码语言:javascript
复制
{
    "name": "hprose/examples",
    "description": "examples of hprose",
    "authors": [
        {   
            "name": "andot",
            "email": "mabingyao@gmail.com"
        }   
    ],  
    "require": {
        "php": ">=5.3.0",
        "hprose/hprose": "dev-master"
    }   
}

执行

代码语言:javascript
复制
composer install

建立server.php

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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);
    }   
});

执行

代码语言:javascript
复制
php server.php
php client.php

结果

代码语言:javascript
复制
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!"
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-11-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档