a ‘weblogUpdates.ping’ - like interface for BritBlog
OK, I’ve been tinkering with this XML-RPC stuff for BritBlog. Basically, I want an interface the same as the Weblogs.Com XML-RPC weblogUpdates.ping method for BritBlog, as I mentioned earlier.
Acording to the documentation, I need to accept the following parameters:
weblogUpdates.ping (weblogname, weblogurl, changesurl=weblogurl, categoryname=”none”) returns struct
To tell Weblogs.Com that a weblog has changed, call weblogUpdates.ping on rpc.weblogs.com, port 80, path /RPC2.
It takes two required parameters, both strings, and two optional parameters, also strings. The first is the name of the weblog, the second is its URL. The third, changesurl, is the url of a page to be checked for changes. The fourth, categoryname, is the name of a category of pings, allowing the weblogs.com interface to be used to track RSS feeds, European weblogs, or whatever.
So I need a method that can accept two, three or four parameters (all strings).
Using the PEAR XML-RPC package I’ve created a framework that doesn’t actually do anything except tell me how many parameters I’ve sent (assuming they are of the correct type):
Listing 1: server.php
<?php require_once 'XML/RPC/Server.php'; /* ** The 'update method'. This will do the work. */ function weblogUpdatePing($params) { switch ($params->getNumParams()) { case 2: $strReturn = "Two params"; $weblogname = $params->getParam(0); $weblogurl = $params->getParam(1); break; case 3: $strReturn = "Three params"; $weblogname = $params->getParam(0); $weblogurl = $params->getParam(1); $changeurl = $params->getParam(2); break; case 4: $strReturn = "Four params"; $weblogname = $params->getParam(0); $weblogurl = $params->getParam(1); $changeurl = $params->getParam(2); $categoryname = $params->getParam(3); break; default: /* ** Should never get here as the method ** signatures will prevent this */ $strReturn = "Invalid parameter count."; break; } $val = new XML_RPC_Value($strReturn, 'string'); return new XML_RPC_Response($val); } /* ** Create a server instance to handle the request. */ $server = new XML_RPC_Server( array( 'weblogUpdates.ping' => array( 'function' => 'weblogUpdatePing', 'signature' => array(array($XML_RPC_String, $XML_RPC_String, $XML_RPC_String), array($XML_RPC_String, $XML_RPC_String, $XML_RPC_String, $XML_RPC_String), array($XML_RPC_String, $XML_RPC_String, $XML_RPC_String, $XML_RPC_String, $XML_RPC_String)) ), ) ); ?>
To test this I used a simple client.
Listing 2 client.php:
<?php require_once 'XML/RPC.php'; /* You can call the method with two, three, or four parameters: $params = array(new XML_RPC_Value('one', 'string'), new XML_RPC_Value('two', 'string'), ); $params = array(new XML_RPC_Value('one', 'string'), new XML_RPC_Value('two', 'string'), new XML_RPC_Value('three', 'string'), ); */ $params = array(new XML_RPC_Value('one', 'string'), new XML_RPC_Value('two', 'string'), new XML_RPC_Value('three', 'string'), new XML_RPC_Value('four', 'string'), ); $msg = new XML_RPC_Message('weblogUpdates.ping', $params); $cli = new XML_RPC_Client('/rpc/server.php', 'localhost'); //$cli->setDebug(1); $resp = $cli->send($msg); if (!$resp) { echo 'Communication error: ' . $cli->errstr; exit; } if (!$resp->faultCode()) { $val = $resp->value(); echo 'return message is ' . $val->scalarval(); } else { /* * Display problems that have been gracefully cought and * reported by the xmlrpc.php script. */ echo 'Fault Code: ' . $resp->faultCode() . "n"; echo 'Fault Reason: ' . $resp->faultString() . "n"; } ?>
So that seems to work as a simple framework. Now I’ve just got to add some logic to:
- check to see if the pings are from BritBlog members,
- check that they haven’t updated recently (say withing 24 hours) - we don’t want ping spammers,
- check that they have really updated their blog by getting their RSS feed,
- Update the ‘recently modified’ page/database stuff.
OK, that’s enough tonight. Anymore work and I’ll have to start to think, which after some Badger’s Tanglefoot and more Fuller’s Golden Pride is probably not possible. Still, time for another beer before bed, me thinks










November 8th, 2005 14:48
[…] ow to develop a ping interface. Including the client side for testing purpose. a ‘weblogUpdates.ping’ - like interface for BritBlog […]
August 3rd, 2006 18:49
Hi Mark,
I have been researching this topic for a few days, and your site gives me the hope i was starting to lose! I am a student that is working on a project that will run an XML-RPC server doing something similar to what weblogs.com is currently doing (and now your site is running). One of the problems that I have already run into is trying to figure out how Wordpress is sending their pings. Since they are using XML-RPC for their pings, I would have figured their data would be coming through a POST or GET string in the HTTP. For testing purposes, I setup a small script that grabs any information that is passed over from a ping and emails me the POST and GET strings. Movable type works perfectly, but Wordpress shows me blank strings. If data is being passed over HTTP, doesn’t it have to be in one of these 2 strings?
Another thing that I have been wondering is if there is a standard for setting up the server. I know that the weblogs will add to their list a link I give them, but what about the method location on my server? I am expecting that I have to put my server in the /RPC2 folder since that is what Weblog.com did (and that seems to be the standard now). I found the following line on the XMLRPC site — ‘To tell Weblogs.Com that a weblog has changed, call weblogUpdates.ping on rpc.weblogs.com, port 80, path /RPC2.’ Is there going to be a specific name that I have to use for the server also?
I know these are a lot of questions, but if you can help out in any way, I would greatly appreciate it!
Thanks in advance,
–Joe Dolan