You are here:  » Ping search engines when sitemap updated


Ping search engines when sitemap updated

Submitted by support on Tue, 2013-06-04 13:39 in

Hi everyone,

Here is a simple ping script to inform search engines that your sitemap has been updated. Save the following as scripts/ping.php

<?php
  
require("../includes/common.php");
  
$host "www.example.com";
  
$sitemap "http://".$host.$config_baseHREF."sitemap.php";
  
$pings = array();
  
$pings[] = "http://www.google.com/webmasters/sitemaps/ping?sitemap=%SITEMAP%";
  
$pings[] = "http://www.bing.com/ping?sitemap=%SITEMAP%";
  
// add any additional search engine PING URLs here
  
foreach($pings as $ping)
  {
    
$ping str_replace("%SITEMAP%",$sitemap,$ping);
    
file_get_contents($ping);
  }
?>

To add additional search engines simply add entries to the $pings array where indicated, using the placeholder %SITEMAP% at the position within the ping URL that should contain your full sitemap URL, for example:

  $pings[] = "http://www.example.com/ping_us?url=%SITEMAP%

ping.php can then be included in your CRON job. In most cases, multiple commands can be included in the same CRON job using semi-colon separation, for example, if your existing command is:

cd /home/example/public_html/scripts/;/usr/bin/php cron.php

...then to include ping.php, use:

cd /home/example/public_html/scripts/;/usr/bin/php cron.php;/usr/bin/php ping.php

Cheers!
David
--
PriceTapestry.com

Submitted by technoarenasol on Thu, 2013-06-20 08:52

technoarenasol

Thank David..Very useful script...

Submitted by BobL on Sat, 2013-06-22 15:33

Bob L.

Thanks David,

It didn't dawn on me you wrote this mod per my request until I seen technoarenasol post.
Probably because you sent the link in an email after I had done a search here for one and couldn't find any.
Works like a charm.

Great work David, and support.
Have a great weekend..

Submitted by Rocket32 on Tue, 2013-07-09 23:53

Is it possible to ping from the a browser url to the scripts folder or you have to use the cron?

Submitted by support on Wed, 2013-07-10 07:38

Hi,

Password protection isn't included in the above example so you could browse directly to /scripts/ping.php

Cheers,
David.
--
PriceTapestry.com

Submitted by BobL on Thu, 2014-07-24 13:10

Bob L.

I don't know if Bing has changed something or not.
But as of late, Bing has not showed the sitemaps has been submitted from this script.
The last submission dates are only showing where I have logged in and submitted them.

Just thought I'd give a heads up here.

Submitted by support on Thu, 2014-07-24 15:58

Hello Bob,

Thanks for that! bing.com's ping URL has indeed changed. I have updated the above script accordingly, for your reference, line 6 was previously:

http://www.bing.com/webmaster/ping.aspx?siteMap=%SITEMAP%

...but is now just:

http://www.bing.com/ping?sitemap=%SITEMAP%

Cheers,
David.
--
PriceTapestry.com

Submitted by BobL on Fri, 2014-07-25 03:31

Bob L.

Thank you, David,

Great support is always appreciated.

Submitted by chrisst1 on Fri, 2014-07-25 12:48

Hi David

Is it possible to run this directly after a full import rather than via cron.

As we import all fortnightly (via cron) I thought it could be useful if this ran automatically at the end of the import rather than setting up many more cron jobs. I'm using the import all to temp table mod.

Chris

Submitted by support on Fri, 2014-07-25 13:00

Hi Chris,

Sure - if you could let me know what CRON command you're currently using, i'll show you how to append the call to this script to your current command - no need to set-up a new cron job...

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Mon, 2014-07-28 12:51

Hi David

The CRON command is as follows:

wget -O /dev/null http://USERNAME:PASSWORD@www.DOMAIN/scripts/cron.php?password=PASSWORD

Thanks

Chris

Submitted by support on Mon, 2014-07-28 14:07

Hello Chris,

As you're using wget, the best thing to do will be to include ping.php at the end of your cron.php

Before you can do this, first edit scripts/ping.php and where you have this code at line 2:

  require("../includes/common.php");

...REPLACE with:

  require_once("../includes/common.php");

With that in place, you can edit your scripts/cron.php and at the very end of the script, on the line before the closing PHP tag add this code:

  require("ping.php");

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Wed, 2014-07-30 10:52

Thanks David

Submitted by stevebi on Thu, 2016-01-21 19:13

Hello David,

When we have multiply sites how should we apply ping for the rest than the main website?

Cheers

Steve

Submitted by support on Fri, 2016-01-22 09:26

Hi Steve,

I notice that you currently have a scripts/ping.php file that you are calling directly from scripts/ping.php by this code at line 156:

  require("ping.php");

That can remain in place for the master website, but since ping.php can run standalone, what I would suggest is adding to your CRON command line calls to ping.php in your other installations, so if your current CRON command line was:

cd /home/example/public_html/scripts/;
/usr/bin/php cron.php;

Then add to the command line:

cd /home/example/public_html/site2/scripts/;
/usr/bin/php ping.php;
cd /home/example/public_html/site3/scripts/;
/usr/bin/php ping.php;

Note that all the above are on a single command line, only separated into new lines for clarity. Separate commands in a single job are separated by semi-colon...

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Fri, 2016-01-22 09:38

Thank you very much David,

Fast and accurate support.

Cheers

Steve