可能你的安裝 會出現一些依賴 通常多是 缺乏 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);
}