同じ解決策を探しています。これは、理論的にはどの XMLRPC サーバーでも機能する非常に単純なクラスです。20分で完成させたので、内省、エラー処理の改善など、まだ多くのことが望まれています.
file: xmlrpcclient.class.php
<?php
/**
* XMLRPC Client
*
* Provides flexible API to interactive with XMLRPC service. This does _not_
* restrict the developer in which calls it can send to the server. It also
* provides no introspection (as of yet).
*
* Example Usage:
*
* include("xmlrpcclient.class.php");
* $client = new XMLRPCClient("http://my.server.com/XMLRPC");
* print var_export($client->myRpcMethod(0));
* $client->close();
*
* Prints:
* >>> array (
* >>> 'message' => 'RPC method myRpcMethod invoked.',
* >>> 'success' => true,
* >>> )
*/
class XMLRPCClient
{
public function __construct($uri)
{
$this->uri = $uri;
$this->curl_hdl = null;
}
public function __destruct()
{
$this->close();
}
public function close()
{
if ($this->curl_hdl !== null)
{
curl_close($this->curl_hdl);
}
$this->curl_hdl = null;
}
public function setUri($uri)
{
$this->uri = $uri;
$this->close();
}
public function __call($method, $params)
{
$xml = xmlrpc_encode_request($method, $params);
if ($this->curl_hdl === null)
{
// Create cURL resource
$this->curl_hdl = curl_init();
// Configure options
curl_setopt($this->curl_hdl, CURLOPT_URL, $this->uri);
curl_setopt($this->curl_hdl, CURLOPT_HEADER, 0);
curl_setopt($this->curl_hdl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl_hdl, CURLOPT_POST, true);
}
curl_setopt($this->curl_hdl, CURLOPT_POSTFIELDS, $xml);
// Invoke RPC command
$response = curl_exec($this->curl_hdl);
$result = xmlrpc_decode_request($response, $method);
return $result;
}
}
?>