<?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');