Hprose for php 初探
因为某些原因审计到使用hprose 的框架的代码。就学习了一下使用方式
一、安装Hprose for PHP
https://hprose.com/
下载到本地。直接调用
使用Hprose制作一个简单的分布式应用程序只需要几分钟的时间。本文将用一个简单的实例来带您快速浏览使用Hprose for PHP进行分布式程序开发的全过程。
二、创建Hprose的Hello服务器
<?php
include("hprose/hproseHttpServer.php");
function hello($name){
return "Hello".$name;
}
$server = new HproseHttpServer();
$server->addFunction("hello"); //发布函数
$server->handle();
?>
本地访问当前的php。会出现Fa1{s5″hello”}z 就说明服务启动成功。
三、创建Hprose的Hello客户端
<?php
include("hprose/hproseHttpClient.php");
$client = new HproseHttpClient("http://localhost/helloserver.php");
echo $client->Hello("Hprose");
?
多种客户端
<?php
include("hprose/hproseHttpClient.php");
$client = new HproseHttpClient("http://www.hprose.com/example/");
echo "<pre>";
echo $client->sum(1, 2, 3, 4, 5);
echo "\r\n";
echo $client->Sum(6.0, 7.0, 8.0);
echo "\r\n";
$userList = $client->getUserList();
print_r($userList);
echo "</pre>";
?>
2、通过Invoke方法进行远程调用
<?php
include("hprose/hproseHttpClient.php");
$client = new HproseHttpClient("http://www.hprose.com/example/");
echo "<pre>";
$args = array(1, 2, 3, 4, 5);
echo $client->invoke("sum", $args);
echo "\r\n";
$args = array(6.0, 7.0, 8.0);
echo $client->invoke("Sum", $args);
echo "\r\n";
$userList = $client->invoke("getUserList");
print_r($userList);
echo "</pre>";
?>

