zoukankan      html  css  js  c++  java
  • [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 HproseSocketServer;
    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 HproseFuture;
    use HproseSocketClient;
    $test = new Client("tcp://127.0.0.1:1314");
    $test->fullDuplex = true;
    Futureco(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!"
  • 相关阅读:
    Go module学习笔记
    java并发基础及原理
    java并发之内存模型
    https理论及实践
    Mysql查询结果导出Excel表
    mysql清空表数据并重置自增ID
    html a标签链接点击闪动问题解决
    rocketmq-console控制台管理界面配置
    nginx多层反代配置变量proxy_set_header
    nginx 实现浏览器文件下载服务
  • 原文地址:https://www.cnblogs.com/taoshihan/p/9960677.html
Copyright © 2011-2022 走看看