下载HessianPHP_v2.0.3.zip
下载地址:http://sourceforge.net/projects/hessianphp/
(不要使用HessianPHP-1.0.5-RC2.zip, 2006年后没有更新了,不支持php5.2以后,及最新hessian协议.
注意:需要注意服务器端发布的hessian协议版本,客户端要与之对应.)
使用例子在:HessianPHP_v2.0.3.zip\quickstart.txt
http://localhost/mathService.php ——–>访问该url时才在服务器端发布hessian.
http://localhost/mathClient.php ———>客户端
其中,涉及三个文件:
Math.php
class Math{
function add($n1,$n2) {
return $n1+$n2;
}
function sub($n1,$n2) {
return $n1-$n2;
}
function mul($n1,$n2) {
return $n1*$n2;
}
function div($n1,$n2) {
return $n1/$n2;
}
}
==========================
mathService.php
include_once ‘Math.php’;
include_once ‘hessianphp/HessianService.php’;
$service = new HessianService(new Math());
$service->handle();
==========================
mathClient.php
include_once ‘hessianphp/HessianClient.php’;
$testurl = ‘http://localhost/yii/testdrive/mathService.php’;
$proxy = new HessianClient($testurl);
try{
echo $proxy->div(2,5);
} catch (Exception $ex){
// …handle error
echo $ex->getMessage();
}
另外,在运行的时候,需要打开php的CURL扩展:C:\xampp\php\php.ini
extension=php_curl.dll