可能你的安装 会出现一些依赖 通常多是 缺乏 m4 autoconfphp
鸟哥博客:http://www.laruence.com/2012/09/15/2779.htmlhtml
安装yar 先安装msgpacknginx
https://github.com/msgpack/msgpack-phpgit
whichis phpize
github
好比个人在:/usr/local/php/bin/phpizeapache
通常php-config也在这里api
个人msgpack 位置在 /home/jshawcx/msgpack-php-master服务器
安装yarphp-fpm
https://github.com/laruence/yaroop
个人yar位置在 /home/jshawcx/yar-1.2.4
cd /xxxx/xxx/msgpack-php-master
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd /xxx/xxx/yar-1.2.4
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
extension=msgpack.so
extension=yar.so
重启php-fpm 和nginx或apache
使用 :
http://php.net/manual/zh/book.yar.php
假如个人ip是 192.168.1.104,个人服务器配置 php文件在 /var/www/yaf
个人server php 就放在 这里好比是api.php, 个人项目入口 index.php 也在这里
<?php class API{ public function add($a,$b){ return $this->_add($a,$b); } public function sub($a, $b) { return $a - $b; } public function mul($a, $b) { return $a * $b; } protected function _add($a,$b){ return $a+$b; } } $server = new Yar_server(new API()); $server->handle(); ?>
个人client index.php
$client = new yar_client("http://192.168.1.104/api.php"); /* call directly */ var_dump($client->add(1, 2)); /* call via call */ var_dump($client->call("add", array(3, 2))); /* __add can not be called */ //var_dump($client->_add(1, 2)); function callback($res,$callinfo){ } Yar_concurrent_client::call("http://192.168.1.104/api.php","add",array(1,2),"callback"); Yar_concurrent_client::call("http://192.168.1.104/api.php","sub",array(2,1),"callback"); Yar_concurrent_client::call("http://192.168.1.104/api.php",'mul',array(2,2),'callback'); Yar_concurrent_client::loop();if ($callinfo == NULL) {
echo "如今, 全部的请求都发出去了, 尚未任何请求返回\n";
} else {
echo "这是一个远程调用的返回, 调用的服务名是", $callinfo["method"],
". 调用的sequence是 " , $callinfo["sequence"] , "\n";
var_dump($retval);
}