You are hereHow To: Implementing Automatic Blog Pinging Using PHP and XML-RPC


How To: Implementing Automatic Blog Pinging Using PHP and XML-RPC


By hagrin - Posted on 10 February 2007

Posted By: hagrin
Date: 14 November 2005

Overview:
In order to run a well-known, successful website or blog, Internet users must be directed and drawn to your site. The draw comes from the content you post and create, but how do people know about the content you have posted on such a vast cyber world? Internet based companies have identified the need to centralize data and content offerings by offering indexing services. Such services, such as Google Blog Search, Technorati and Weblogs Inc., are indexing services specifically designed to publicize blogging content. However, unlike Google's main search engine, these services do not crawl the Internet on their own to find new content. Instead, these services need to be contacted by the blog/site owner either through a manual "pinging" or by automatically pinging the service through a remote procedure call. Obviously, webmasters do not want to maintain manual processes to promote their site so automatically contacting these indexing services is preferred. The following explains how to accomplish automatic blog pinging utilizing PHP and XML-RPC.

What You Need:
To automate the blog pining process, you will need the following:

  1. A website written in PHP and a PHP installation on your web server
  2. XML-RPC for PHP class library
  3. Weblog_Pinger class library

Automation Process:
Now that you have the tools needed to complete the process, an implementation plan is needed. So where do we begin?

1) Where and when should the pinging process occur? - For the most effecient and effective result from automatic pinging, you want to choose a place in your posting procedure that ensures that an automatic ping signals new content on your site. For 99% of blogs, you will want to add the necessary code after a successful post or publishing of new content. Why? Well, simply, since your blog has fresh, new content, you will want to notify all blog indexing services immediately. However, for sites that post new content in extremely large quantities (which isn't suggested since most users will not want to sift through 50+ new posts a day), you might want to consier adding the code in an hourly cron job because you do not want your site to get delisted for abusing the pinging service and "flooding" their services.

2) The Actual Code - So, after determining that you want to add your code after a successful post/publishing of your blog, let's examine exactly what you will need to do. Most likely, you have written code (or see code if you are using a third party app) that holds a SQL Insert statement. After the SQL query code, you need to add the PHP code necessary to ping the blog indexing services. That code should look something like the following:

// After SQL Insert Code ...

require 'weblog_pinger.php';

The "require" statement should be followed by the correct path for where you saved the weblog_pinger.php file (item #3 from the "What You Need" section). In the example above, the PHP page that performs my post submissions and blog republishing is located in the same directory as my weblog_pinger.php file. After the require statement, you should add:

$pingblogs = new Weblog_Pinger();
$pingblogs->ping_all("Name of Your Blog", "http://www.hagrin.com", "", "");

So what does this code do? The first line says to use the variable $pingblogs (you can name the variable anything you want, I chose $pingblogs arbitrarily) and create a new object instance using the Weblog_Pinger class. This class is specified in the weblog_pinger.php file you "required" above. The second line uses our new $pingblogs variable and calls the ping_all function which will send your information to three sources - Technorati, Weblogs and Blo.gs (there are other functions available to call, but for the purposes of the tutorial, I chose to use the ping_all function for simplicity). After the calling of the "ping_all" function, you will notice 4 items encapsulated within quotes and separated by commas. The first item declares the name of your blog (in this example, "Name of Your Blog"). The second item, http://www.hagrin.com, specifies the URL where your blog is located. Item three, which I have left without a value, is the "change URL". This URL represents where the actual new content is located. It is not necessary to declare a change URL - the default value automatically returns the URL where your blog is located (the second item in the ping_all function). Last but not least, the fourth item holds the category your blog should be submitted into (the default value is none).

And that's it!!! You don't need any additional code to get the basic features working which are good enough to get you listed in all the blog indexing services you need to promote your content.

Resources:

  1. Workbench Blog by Rogers Cadenhead

Version Control:

  1. Version 1.0 - 15 November 2005 - Original Article