咸鱼韭菜

专注LANMP

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
<?php
class RpcController extends Yaf_Controller_Abstract {

    //RPC入口
    public function indexAction($class_name) {
        $class_name = 'Rpc_'.$this->g_ucfirst('_', $class_name);
        if(!@class_exists($class_name)) {
            die("No such class of ". $class_name);
        }
        $server = new Yar_Server(new $class_name());
        $server->handle();
        return false;
    }

    private function g_ucfirst($separator, $string) {
        if(strpos($string, $separator) !== false) {
            $string = explode($separator, strtolower($string));
            $arr = array();
            foreach($string as $v) {
                $arr[] = ucfirst($v);
            }
            return implode($arr, $separator);
        } else {
            return ucfirst(strtolower($string));
        }
    }
}
使用Rpc
$client
= new Yar_Client('http://www.pengcz.com/Rpc/push');

 

posted on 2017-02-23 13:43  咸鱼韭菜  阅读(189)  评论(0)    收藏  举报