If you are familiar with blogosphere you know what is Technorati.
Technorati is an Internet search engine for searching blogs. You can submit your blog to Technorati and ping their servers when your blog site is updated. when you ping Technorati their web crawlers read the updated information on your site.
Technorati offers an XML-RPC ping web service to allow blogs to notify content changes.
In this article we discuss how to write a PHP script to programatically ping Technorati when there is new content in your site.
The URL to ping is rpc.technorati.com/rpc/ping.
The method name to call is weblogUpdates.ping.
The request XML must contain two parameters – your blog site name the blog site URL.
From the API documentation of Technorati, the sample request XML is as below:
<?xml version="1.0"?>
weblogUpdates.ping
YOUR WEBLOG NAME HERE
http://www.YOURWEBLOGURL.com/Let’s start writing the XML-RPC client to ping Technorati.
Our first step is to generate the required XML request string.
<?php $site_name = "YOUR WEBLOG NAME HERE"; $site_url = "http://www.YOURWEBLOGURL.com"; $request = xmlrpc_encode_request("weblogUpdates.ping", array($site_name, $site_url)); ?>
The function xmlrpc_encode_request as the name suggests, creates the request XML string. If you echo $request variable you will see output like below:
<?xml version="1.0" encoding="iso-8859-1"?>
weblogUpdates.ping
Benzing Technologies
http://benzingtech.comThe next step is to create the streams context.
<?php $context = stream_context_create(array('http' => array( 'method' => "POST", 'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\nHost: rpc.technorati.com\r\n", 'content' => $request ))); ?>
The code snippet states that we are preparing to make an HTTP POST request to the server rpc.technorati.com.
The next step is to make the request.
<?php $server = "http://rpc.technorati.com/rpc/ping"; $file = file_get_contents($server, false, $context); ?>
We now decode the response XML using the function xmlrpc_decode(). We determine whether the response XML contains a fault structure using the xmlrpc_is_fault() function.
<?php $response = xmlrpc_decode($file); if (is_array($response) and xmlrpc_is_fault($response)){ echo "Failed to ping Technorati"; } else { echo "Successfully pinged Technorati"; } ?>
The entire script is pasted below.
<?php $site_name = "Benzing Technologies"; /** * The URL of your site */ $site_url = "http://benzingtech.com"; $request = xmlrpc_encode_request("weblogUpdates.ping", array($site_name, $site_url)); #echo $request; $context = stream_context_create(array('http' => array( 'method' => "POST", 'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\nHost: rpc.technorati.com\r\n", 'content' => $request ))); $server = "http://rpc.technorati.com/rpc/ping"; $file = file_get_contents($server, false, $context); $response = xmlrpc_decode($file); if (is_array($response) and xmlrpc_is_fault($response)){ echo "Failed to ping Technorati"; } else { echo "Successfully pinged Technorati"; } ?>
The source code is available from the Code Album Github repository.
6 Responses to Use PHP to Ping Technorati on your blog updates
Use bPHP/b to Ping Technorati on your blog updates | Benzing b…/b
September 15th, 2009 at 1:58 pm
[...] Use bPHP/b to Ping Technorati on your blog updates | Benzing b…/b SHARETHIS.addEntry({ title: "Use bPHP/b to Ping Technorati on your blog updates | Benzing [...]
September 19th, 2009 at 8:34 pm
Hey there,
Great blog, I just stumbled upon it and I am already a fan.
How to Secure your Wireless Broadband | Business BroadBand
October 21st, 2009 at 12:01 pm
[...] Use PHP to Ping Technorati on your blog updates « Benzing … [...]
Blog Ping To Boost Traffic
November 25th, 2009 at 12:58 am
Blog Ping To Boost Traffic…
SEO technology changes at a rapid pace and you’ d need to spend lot of time to keep yourself updated to the latest techniques in SEO. SEO can be a time consuming process. As a businessman, you need to spend your time in developing and growing your busi…
December 17th, 2009 at 5:19 am
Can we ping custom web sites using this code or we need ping only blog ?
December 18th, 2009 at 12:16 pm
No, just replace the url’s and names with your site or which ever site you want.