设为首页 加入收藏

TOP

[PHP]PHP rpc框架hprose测试
2019-08-23 00:39:05 】 浏览:20
Tags: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!"

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇PhpStorm 中切换PHP版本 下一篇字符串常用函数

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目