<?
// PHPRPC Client (c) Gregory A. Rozanoff, 2005
// RPC::Proxy class
class RPC {
function &Proxy ($url) {
$rpc_proxy = new phprpcClient($url);
$client = $rpc_proxy->create_RPC();
eval($client);
return new $rpc_proxy->cName;
}
}
// phprpc client class
class phprpcClient {
var
$cName = "RPC_Client",
$blocksize = 4096,
$version = "PHPRPC Client v 0.2.7 (c) Gregory A. Rozanoff, 2005";
function phprpcClient($src) { $this->src = $src; }
function create_RPC() {
$start = $this->get_microtime();
$tmp = $this->transport(array("defun" => "_namespace"));
$uptime = round(($this->get_microtime() - $start) * 1000000) / 1000;
$namespace = unserialize($tmp);
$cls = 'class '.$this->cName.' extends phprpcClient {
function '.$this->cName.'() {
$this->src = "'.$this->src.'";
$this->uptime = '.$uptime.';
}';
foreach ($namespace as $foo) $cls .= '
function '.$foo.'() {
$args = func_get_args();
return $this->execute("'.$foo.'", $args);
}';
return $cls."\n}";
}
function execute($foo, $args) {
$f = serialize(array('foo' => $foo, 'args' => $args));
$data = $this->transport(array("defun" => $f));
return unserialize($data);
}
function transport($fields) {
$urn = parse_url($this->src);
if (!$urn['port']) $urn['port'] = 80;
foreach ($fields as $name => $value)
$data .= urlencode($name)."=".urlencode($value)."&";
$query =
"POST {$urn['path']} HTTP/1.0\r\n".
"User-Agent: {$this->version}\r\n".
"Host: {$urn['host']}\r\n".
"Connection: close\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: ".strlen($data)."\r\n\r\n".$data;
if ($fp = fsockopen($urn['host'], $urn['port'])) {
if (!fputs($fp, $query, strlen($query))) exit;
while (!feof($fp)) $tmp .= fread($fp, $this->blocksize);
fclose($fp);
$m = preg_split("/(\r?\n){2}/s", $tmp);
return urldecode(trim($m[1]));
}
return FALSE;
}
function get_microtime() {
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
}
?>