I wrote a small PHP application several months ago that uses the WordPress XMLRPC library to synchronize two separate WordPress blogs. I have a general "RPCRequest" function that packages the request, sends it, and returns the server response, and I have several more specific functions that customize the type of request that is sent.
In this particular case, I am calling "getPostIDs" to retrieve the number of posts on the remote server and their respective postids. Here is the code:
$rpc = new WordRPC('http://mywordpressurl.com/xmlrpc.php', 'username', 'password');
$rpc->getPostIDs();
I'm receiving the following error message:
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:
Kind of a cliffhanger ending, which is also strange. But since the error message isn't formatted in XML, my intuition is that it's the local XMLRPC library that is generating the error, not the remote server.
Even stranger, if I change the "getPostIDs()" call to "getPostIDs(1)" or any other integer, it works just fine.
Here is the code for the WordRPC class:
public function __construct($url, $user, $pass) {
$this->url = $url;
$this->username = $user;
$this->password = $pass;
$id = $this->RPCRequest("blogger.getUserInfo",
array("null", $this->username, $this->password));
$this->blogID = $id['userid'];
}
public function RPCRequest($method, $params) {
$request = xmlrpc_encode_request($method, $params);
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request
)));
$file = file_get_contents($this->url, false, $context);
return xmlrpc_decode($file);
}
public function getPostIDs($num_posts = 0) {
return $this->RPCRequest("mt.getRecentPostTitles",
array($this->blogID, $this->username,
$this->password, $num_posts));
}
As I mentioned, it works fine if "getPostIDs" is given a positive integer argument. Furthermore, this used to work perfectly well as is; the default parameter of 0 simply indicates to the RPC server that it should retrieve all posts, not just the most recent $num_posts
posts. Only recently has this error started showing up.
I've tried googling the error without much luck. My question, then, is what exactly does "expat reports error code 5" mean, and who is generating the error? Any details/suggestions/insights beyond that are welcome, too!