zoukankan      html  css  js  c++  java
  • phprpc的简单使用

    1.phprpc简介

    是一个轻型的、安全的、跨网际的、跨语言的、跨平台的、跨环境的、跨域的、支持复杂对象传输的、支持引用参数传递的、支持内容输出重定向的、支持分级错误处理的、支持会话的、面向服务的高性能远程过程调用协议。

    phprpc是基于数据序列化和传输,优于传统的WebService,如soap。

    PHPRPC支持多种语言包括,ASP,PHP,JAVA,C++,JAVASCRIPT,PYTHON等。官网:http://phprpc.org/zh_cn/  (我现在访问不了了,开启了翻墙也不行,原因没有找到)

    1.1  下载phprpc for php 的安装安装包解压

      目录:

        其中bigint.php、compat.php、phprpc.php、phprpc_date.php、xxtea.php 这些属于公共文件。不论是客户端还是服务器都需要有这些文件。

        phprpc_client.php,是客户端文件,在客户端php文件里只需要应用这个文件就可以了它会自动包含公共文件。

        dhparams、dhparams.php、phprpc_server.php 这三个是服务器端需要的文件。其中dh-params目录中包含的是加密传输时生成密钥的参数。dhparams.php用来读取dhparams目录中的类。phprpc_server.php是服务端文件,如果使用php发布PHPRPC服务,只需要包含着文件就可以了。公共文件和dhparams.php不需要单独包含。

    2.案例

      2.1 服务器端 

    include('../phprpc_server.php');
    
    class Hello{
        static function helloWorld(){
            return "hello world";
        }
    }
    
    $server = new PHPRPC_Server();
    
    $server->add('helloWorld','hello');
    $server->start();

      2.2 客户端

    include("../phprpc_client.php");
    
    $client = new PHPRPC_Client('http://www.test.com/phprpc/test/server.php');
    
    
    echo $client->helloWorld();

    注意:1 执行出现:Cannot redeclare gzdecode()

    原因:php在5.4版本后,已经自包含了gzdecode()函数,开发者自己定义的gzdecode()函数会与其冲突。

    解决:在compat.php文件里

    if (! function_exists('gzdecode')) {
        //将gzdecode函数包括进来
     }

    注意:2 Methods with the same name as their class will not be constructors in a future version of PHP; PHPRPC_Date has a deprecated constructor

    原因:PHP 7开始使用和类名相同的方法名作为构造方法会报E_DEPRECATED级别的错误,提示在未来版本中会彻底抛弃类同名方法作为构造函数。

    3.hprose是商业版本,功能更加强大;

    网上的资料都是很多年前的了,可能现在真的用的很少了,我先项目中大部分也是使用curl;

  • 相关阅读:
    .NetCore Grpc 客服端 工厂模式配置授权
    DOCKER 拉取 dotnet 镜像太慢 docker pull mcr.microsoft.com too slow
    Introducing .NET 5
    VSCode 出现错误 System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached.
    Omnisharp VsCode Attaching to remote processes
    zookeeper3.5.5 centos7 完全分布式 搭建随记
    Hadoop2.7.7 centos7 完全分布式 配置与问题随记
    MySQL索引 索引分类 最左前缀原则 覆盖索引 索引下推 联合索引顺序
    SQL基础随记3 范式 键
    MySQL调优 优化需要考虑哪些方面
  • 原文地址:https://www.cnblogs.com/myvic/p/8243248.html
Copyright © 2011-2022 走看看