// Storage place for an error message
function __construct( $server, $path = false, $port = 80, $timeout = 15 )
// Assume we have been given a URL instead
$bits = parse_url($server);
$this->server = $bits['host'];
$this->port = isset($bits['port']) ? $bits['port'] : 80;
$this->path = isset($bits['path']) ? $bits['path'] : '/';
// Make absolutely sure we have a path
if ( ! empty( $bits['query'] ) ) {
$this->path .= '?' . $bits['query'];
$this->useragent = 'The Incutio XML-RPC PHP Library';
$this->timeout = $timeout;
public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) {
self::__construct( $server, $path, $port, $timeout );
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
* to the function signature.
function query( ...$args )
$method = array_shift($args);
$request = new IXR_Request($method, $args);
$length = $request->getLength();
$xml = $request->getXml();
$request = "POST {$this->path} HTTP/1.0$r";
// Merged from WP #8145 - allow custom headers
$this->headers['Host'] = $this->server;
$this->headers['Content-Type'] = 'text/xml';
$this->headers['User-Agent'] = $this->useragent;
$this->headers['Content-Length']= $length;
foreach( $this->headers as $header => $value ) {
$request .= "{$header}: {$value}{$r}";
echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n";
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
$fp = @fsockopen($this->server, $this->port, $errno, $errstr);
$this->error = new IXR_Error(-32300, 'transport error - could not open socket');
$line = fgets($fp, 4096);
if (strstr($line, '200') === false) {
$this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
// merged from WP #12559 - remove trim
echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n";
// Now parse what we've got back
$this->message = new IXR_Message($contents);
if (!$this->message->parse()) {
$this->error = new IXR_Error(-32700, 'parse error. not well formed');
// Is the message a fault?
if ($this->message->messageType == 'fault') {
$this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
// methodResponses can only have one param - return that
return $this->message->params[0];
return (is_object($this->error));
return $this->error->code;
function getErrorMessage()
return $this->error->message;