1. 安装yar
https://github.com/laruence/yar
$phpize
$configure --with-php-config=/path/to/php-config/ --enable-msgpack
$make && make install
注意为了真实可以在client服务器上再装一个yar扩展
2. server 端 文件 yar_server.php
<?php
class API{
public function api($parameter,$option="foo"){
//echo 'parameter'; //
return $parameter;
}
protected function client_can_not_see(){
}
}
$service = new Yar_Server(new API());
$service->handle();
注意:不能echo 只会导致client 端访问时报错
3. client端 文件 yar_client.php
<?php
$client = new Yar_Client("http://game.zhaozhiliang.cn/yar_server.php");
echo $client->api("I am client");
/usr/local/php/bin/php yar_client.php //php 打全路径最好
或者使用 http://yiqivm.com/yar_client.php 访问都可以
也在在同一台服务器既是client 又是 server