Yar轻量级、可串行也可并行、可通过get方法查看接口列表和注释,只需要把接口信息整理好,就能在查看接口的时候同时查看接口文档了。
Yar是啥
轻量级、并行php RPC框架,只支持php程序之间的相互调用。
优点:轻量级、可串行也可并行、可通过get方法查看接口列表和注释,只需要把接口信息整理好,就能在查看接口的时候同时查看接口文档了。
缺点:不支持跨语言调用。
安装
git clone https://github.com/laruence/yar.git
phpize
./configure
make & make install
// 安装成功后,在php.ini中添加extension=yar.so,重启fpm即可
./configure报错
configure: error: Please reinstall the libcurl distribution - easy.h in <curl-dir>/include/curl/
需要安装apt-get install libcurl4-gnutls-dev
yar支持php、json和Msgpack三种打包工具,默认是php,如果要用Msgpack的话要先安装Msgpack扩展,然后配置时加上--enable-msgpack参数。但实际使用中发现,php的serialize和msgpack的效率几乎差不太多,甚至serialize性能还要好一点点,不过serialize所占的空间要稍大一些,个人认为没有必要用msgpack。
php服务端代码
<?php
// this is a yar server
Class Api{
/**
* this is a comments
* api documents writes here
*/
function add($a,$b){
return $a+$b;
}
function mult($a,$b){
return $a*$b;
}
protected function _add(){
return 'this can\'t be seen by client';
}
}
$server = new Yar_Server(new Api(