Weblogs.com Ping Cacher in PHP
Like many other weblogging systems, ours sends an XML-RPC ping to Weblogs.com whenever a new item appears. Weblogs.com is a busy server though, and when we do this is “real time” there’s an 5 or 10 second delay before the ping is finished during which authors have to sit and wait.
As a way of working around this, we’ve set up a “ping cacher.” Ping requests are dumped into a MySQL database by the weblog authoring system, and then a cron job does the actual pinging, checking once a minute to see if there’s any new items deserving of a ping.
To keep things simple and universal, we set up our own XML-RPC server that mirrors exactly the XML-RPC parameter format of the Weblogs.com web service at rpc.weblogs.com/RPC2. Ours lives at www.reinvented.net/RPC2 and, just like Weblogs.com, accepts a request with two parameters, weblogname and weblogurl.
Pings to our XML-RPC service are dumped into a MySQL database, and then a cron job checks once a minute for new items that haven’t had a ping sent for them; if the cron jobs finds one, it sends an XML-RPC message to the rpc.weblogs.com/RPC2 and marks the item in the database as having been “pinged for.”
We used the useful inc. PHP XML-RPC implementation (update: this code has moved here, and recent changes may require tweaks to the function names in my code) to build the server and the client.
We’re making the code available under a Creative Commons Attribution-ShareAlike license:
- WeblogsPingCacher.tar.gz [2KB]
There are two scripts included: index.php is the XML-RPC server that mimics the Weblogs.com ping server and ping.php, which assumes you have installed a CGI version of PHP, runs as a cron job.
Our implementation assumes you use MySQL as a database server, but of course it would be easy to substitute any database server with a few modifications.

Comments