<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>上善若水 &#187; PHPRPC</title>
	<atom:link href="http://iiiorz.net/tag/phprpc/feed/" rel="self" type="application/rss+xml" />
	<link>http://iiiorz.net</link>
	<description>如果我不能死在一万个敌人的包围中，那就让我死在一万个美女的怀抱中吧</description>
	<lastBuildDate>Fri, 19 Nov 2010 04:05:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>kohana中使用PHPRPC</title>
		<link>http://iiiorz.net/2009/11/kohana%e4%b8%ad%e4%bd%bf%e7%94%a8phprpc/</link>
		<comments>http://iiiorz.net/2009/11/kohana%e4%b8%ad%e4%bd%bf%e7%94%a8phprpc/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 08:09:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[kohana]]></category>
		<category><![CDATA[PHPRPC]]></category>

		<guid isPermaLink="false">http://iiiorz.net/?p=78</guid>
		<description><![CDATA[kohana版本: 2.34 PHPRPC介绍： PHPRPC 以下是实现kohana 使用 PHPRPC的具体实例，已经应用在一具体的项目中。功能不算强大，算是抛砖引玉吧。 Library 中 Rpc.php 服务器上Controllers中的 server.php 服务器端事物处理文件 Library 中 As_user.php 客户端测试Controllers 代码]]></description>
			<content:encoded><![CDATA[<p>kohana版本: 2.34<br />
PHPRPC介绍： PHPRPC</p>
<p>以下是实现kohana 使用 PHPRPC的具体实例，已经应用在一具体的项目中。功能不算强大，算是抛砖引玉吧。</p>
<p>Library 中 Rpc.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php defined('SYSPATH') OR die('No direct access allowed.');

class RPC_Core {

private static $instance;

private static $data;

private static $server;

private $phprpc;

public static function instance()
{
if (!isset(self::$instance))
{
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}

public function __construct()
{
//self::$server = &quot;http://172.16.7.5&quot;;
$this-&gt;phprpc = TRUE;
$this-&gt;phprpc = FALSE;
self::$server = &quot;http://site.fj&quot;;
}

public function __call($name, $args){

$class = $name;

$method = $args[0];

$args = array_slice($args,1);

if($this-&gt;phprpc)
{
require_once(MODPATH.'phprpc/phprpc_client.php');
$client = new PHPRPC_Client(self::$server.'/server/data/'.$class.'/'.$method);
return $client-&gt;{$method}($args);
}else{
$class = 'As_'.$class;
$class = new $class;
return $class-&gt;{$method}($args);
}
}
}
</pre>
<p>服务器上Controllers中的 server.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php defined('SYSPATH') OR die('No direct access allowed.');

class Server_Controller extends Controller {

public function data($class)
{
$method = $this-&gt;uri-&gt;segment(4);
require_once(MODPATH.'phprpc/phprpc_server.php');

$server = new PHPRPC_Server();
$class = 'As_'.$class;
$server-&gt;add($method , new $class);
$server-&gt;start();
}
}
</pre>
<p>服务器端事物处理文件 Library 中 As_user.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php defined('SYSPATH') OR die('No direct access allowed.');
class As_user_Core {
public function hello($name)
{
return 'hello world '.kohana::debug($name);
}

public function test()
{
return '-m-';
}
}
</pre>
<p>客户端测试Controllers 代码</p>
<pre class="brush: php; title: ; notranslate">
public function test()
{
echo 'rpc test ...................................&lt;br/&gt;';
$rpc = Rpc::instance();
echo $rpc-&gt;user('hello',$class='class',$name='1');
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://iiiorz.net/2009/11/kohana%e4%b8%ad%e4%bd%bf%e7%94%a8phprpc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

