PHP code to ping Google Bing and Ask.com

What is meant by Search Engine Ping?

Lets understand the concept with an example.You have a blog in place.You regularly update the blog with new content.After updating the content the next part if informing everyone about the new content.In this list search engines like Google and Bing are also included.

As part of Search Engine Optimization most bloggers add XML sitemap to Google Webmasters and Bing Webmasters.

Sitemaps content URL of all your content.This enables search engine to know about content on your website.After adding new post on your site sitemaps should be updated.Search Engines should be informed about the updated content.This task can be accomplished by pinging your sitemap URL to search engines.

Pinging search engines like Google Bing and Ask.com is important feature for sitemap generating plugins.This enables you to inform about your site changes instantly.This also increases crawl rate of your website.I added this feature in my image sitemap and mobile sitemap plugins for WordPress.The code is on Github (Github PHP Code) as well.Below is the code along with explanation.

Code Explanation and details

You can use the code in other PHP based content management system.It only used one WordPress specific function.There are equivalent PHP functions you can use.Also other content management systems also provide similar functions.So you can check your content management system to look for appropriate function.

Ping Google

$udinra_tempurl = 'http://udinra.com/sitemap-image.xml";
$udinra_ping_url = '';
$udinra_ping_url = "http://www.google.com/webmasters/tools/ping?sitemap=" . urlencode($udinra_tempurl);
$udinra_response = wp_remote_get( $udinra_ping_url );
if($udinra_response['response']['code']=200)
{
$udinra_sitemap_response = "Pinged Google Successfullyn";
}
else {
$udinra_sitemap_response = "Failed to ping Google.";}

On the first line I am initializing the variables to sitemap file location URL.The ping URL to google is created by appending encoded sitemap URL to Google URL for pinging sitemaps.The function wp_remote_get() is WordPress function.You can search for similar function on your content management system and use that.Response code of 200 is returned is ping is successful else ping was not successful.

You can read in detail about wp_remote_get function at this WordPress codex link.

Ping Bing

$udinra_tempurl = 'http://udinra.com/sitemap-image.xml";
$udinra_ping_url = '';
$udinra_ping_url = "http://www.bing.com/webmaster/ping.aspx?sitemap=" . urlencode($udinra_tempurl);
$udinra_response = wp_remote_get( $udinra_ping_url );
if($udinra_response['response']['code']=200)
{
$udinra_sitemap_response = "Pinged Bing Successfullyn";
}
else {
$udinra_sitemap_response = "Failed to ping Bing.";
}

For details of the code you can refer the description section of Ping Google above.If you closely analyze the code you can see that entire code is same as that of above.The only thing changed is the ping url.In first case it was of Google and in second case it is of Bing.

Ping Ask.com

$udinra_tempurl = 'http://udinra.com/sitemap-image.xml";
$udinra_ping_url ='';
$udinra_ping_url = " " . urlencode($udinra_tempurl);
$udinra_response = wp_remote_get( $udinra_ping_url );
if($udinra_response['response']['code']=200)
{
$udinra_sitemap_response = "Pinged Ask.com Successfullyn";
}
else {
$udinra_sitemap_response = "Failed to ping Ask.com.";
}

The above code used to work for Ask.com but recently I found problem with this code.Since nothing was changed in the code I thought to debug it.It was throwing WP_ERROR object as response of the ping.I modified above ping code to display the response using var_dump function of PHP.This function might not be liked by some but it does print everything it has and is quite useful for debugging.

The output printed by var_dump function is shown below

object(WP_Error)[39]
  public 'errors' =>
    array
      'http_request_failed' =>
        array
          0 => string 'Could not resolve host: submissions.ask.com; Host not found' (length=59)
  public 'error_data' =>
    array
      empty

Looking at the response returned from ping it seems that submissions.ask.com is not available currently.
So any efforts to ping sitemap will fail.It seems that Ask.com has ended pinging support.

Conclusion

I would be updating this post in future with more search engine ping code.You can also contribute on Github page of this post.The code can be ported to other programming language like Python or Ruby without any issues.I would be writing new post on these languages.So stay tuned.

10 thoughts on “PHP code to ping Google Bing and Ask.com

  1. cool i like it. thanks for shared

  2. cool i like it. thanks for shared

  3. Good article Esha. Do I copy paste the script above on my functions.php? I am sorry I do not understand

    • This code is used to ping these search engines (generally your sitemap files)..You can use codes any where you want..just copy paste will work without any issues..Ask.com recently had issues pinging so avoid ask.com code..How you are planning to use it? (functions.php ??)

  4. Thank you. I pasted in functions.php, it’s lot safer for a newbie like me 🙂

    • welcome..good to know you found this useful..consider sharing the post in case you found this useful

  5. thanks for the code i used this code on my php website Do check my website

  6. What’s about ask.com ping. heheheh

    • Ask.Com is not allowing it anymore.

  7. thanks for share

Leave a Comment