I built a PHP script a few months back that connects two WordPress sites using the XML-RPC API. Everything was working great until recently when I started getting a weird error.
I have a custom class that handles the XML-RPC communication and I’m trying to fetch post information from a remote WordPress site. Here’s my simplified code:
$client = new WPSyncClient('http://example-site.com/xmlrpc.php', 'myuser', 'mypass');
$client->fetchPostList();
But now I’m getting this error:
expat reports error code 5
description: Invalid document end
line: 1
column: 1
byte index: 0
total bytes: 0
data beginning 0 before byte index:
The weird part is that if I pass any number as a parameter like fetchPostList(5), it works perfectly. Here’s my class structure:
class WPSyncClient {
public function __construct($endpoint, $user, $pass) {
$this->endpoint = $endpoint;
$this->user = $user;
$this->pass = $pass;
$userInfo = $this->makeRequest("blogger.getUserInfo",
array("null", $this->user, $this->pass));
$this->siteID = $userInfo['userid'];
}
public function makeRequest($method, $args) {
$requestData = xmlrpc_encode_request($method, $args);
$httpContext = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $requestData
)));
$response = file_get_contents($this->endpoint, false, $httpContext);
return xmlrpc_decode($response);
}
public function fetchPostList($limit = 0) {
return $this->makeRequest("mt.getRecentPostTitles",
array($this->siteID, $this->user,
$this->pass, $limit));
}
}
This used to work fine when I passed 0 as the default parameter (which tells the server to return all posts). The error only started happening recently and I can’t figure out what changed.
What does this expat error code 5 actually mean and where is it coming from? Is it from my local XML parser or the remote server?