PHPRPC 是一个轻型的、安全的、跨网际的、跨语言的、跨平台的、跨环境的、跨域的、支持复杂对象传输的、支持引用参数传递的、支持内容输出重定向的、支持分级错误处理的、支持会话的、面向服务的高性能远程过程调用协议。 遇到的问题总结: Fatal error: Cannot redeclare gzdecode() in 1、重命名compat.php、phprpc_client.php的gzdecode(和系统函数冲突)函数为gzdecode_other Non-static method PHPRPC_Server::initSession() should not be called statically 2、修改phprpc_server.php文件里面initSession函数的类型为static即可。 3、phprpc_client.php 472行警告: Notice: Undefined offset in phprpc_client.php line 472 修改成 $arr = explode('=', $c, 2); if(count($arr)>1) { list($name, $value)=$arr; if (!in_array($name, array('domain', 'expires', 'path', 'secure'))) { $_PHPRPC_COOKIES[$name] = $value; } } 4、Warning: The magic method __get() must have public visibility and cannot be static in compat.php(235) : eval()'d code on line 3 改成public: eval(' class ' . $classname . ' { public function __get($name) {
php server端 <?php
include ('php/phprpc_server.php'); include 'entitys.php'; function hello($name) { return 'Hello ' . $name; } $server = new PHPRPC_Server(); $server->setCharset('UTF-8'); $server->setDebugMode(true); $server->setEnableGZIP(true); $server->add('hello'); $server->add('sort'); $server->add('getcwd'); $server->add('add', new Calculator()); $server->add('mul', new Calculator()); $server->add('div', new Calculator()); $server->add('sub', new Calculator()); $server->add('fuck', new Calculator()); $server->add('getstudent', new Calculator()); $server->add('getstudents', new Calculator()); $server->start(); ?>
<?php class Student { public $id; public $name; public $age; } class Calculator { public function add($x, $y) { return $x + $y; } public function sub($x, $y) { return $x - $y; } public function mul($x, $y) { return $x * $y; } public function div($x, $y) { return $x / $y; } public function fuck($str, $x, $y) { $m = $x + $y; return 'fuck 日本' . $str . $m; } public function getstudent($student) { $student = new Student(); $student->id = 110; $student->name = 'php'; $student->age = 21; return $student; } public function getstudents($id) { $entitys = array(); for ($i=0;$i<10;$i++) { $student = new Student(); $student->id = $i; $student->name = '中文php'.$i; $student->age = 21; array_push($entitys, $student); } return $entitys; } } ?>
php client客户端
<?php
include ("php/phprpc_client.php"); $client = new PHPRPC_Client('http://localhost/phprpc/index.php'); echo '<br/>'; $ret=$client->add(12,32); print_r($ret); echo '<br/>'; $ret=$client->mul(12,32); print_r($ret); echo '<br/>';
|