ubuntu 安装yar和使用

可能你的安装 会出现一些依赖  一般可能是  缺少 m4   autoconf

鸟哥博客:http://www.laruence.com/2012/09/15/2779.html

安装yar 先安装msgpack

https://github.com/msgpack/msgpack-php

 whichis phpize

比如我的在:/usr/local/php/bin/phpize

一般php-config也在这里

我的msgpack 位置在 /home/jshawcx/msgpack-php-master

安装yar

https://github.com/laruence/yar

我的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){
  if ($callinfo == NULL) {
        echo "现在, 所有的请求都发出去了, 还没有任何请求返回\n";
     } else {
              echo "这是一个远程调用的返回, 调用的服务名是"$callinfo["method"], 
                      ". 调用的sequence是 " $callinfo["sequence"] , "\n";
        var_dump($retval);
     }
} 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();

 

转载于:https://www.cnblogs.com/Sven-w/p/4278145.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值