Thanks in advance to those who assist.
I am in the process of writing a content management system for niche sites. Presently the program writes to and updates an xml sitemap when the user clicks the appropriate link.
I would like to add a "ping feature" to the script that would ping the various search engines once the user has completed adding or editing pages. I searched this forum and found this script:
<?php
function ping($server) {
$ping = shell_exec('ping -c 2 -t 5 ' . $server . '');
#$reply = preg_match('/([0-2]) packets received/', $ping, $data);
$reply = preg_match('/([0-2]) received/', $ping, $data);
$packets = intval($data[1]);
if($packets>0)
{
$status = "<font color=\"green\">Online</font>";
}
elseif($packets==0)
{
$status = "<font color=\"red\">Offline</font>";
}
else
{
$status = "<font color=\"black\">Unknown</font>";
}
return $status;
}
// Test ping: Google.com
#ping('www.google.com');
echo ping('www.ironchefbadass.com');
?>
My interpretation:
<?php
function ping($server) {
$ping = shell_exec('ping -c 2 -t 5 ' . $server . '');
$reply = preg_match('/([0-2]) packets received/', $ping, $data);
$packets = intval($data[1]);
if($packets>0)
{
$status = "<font color=\"green\">Online</font>";
}
elseif($packets==0)
{
$status = "<font color=\"red\">Offline</font>";
}
else
{
$status = "<font color=\"black\">Unknown</font>";
}
return $status;
}
// Test ping: Google.com
ping('www.google.com');
echo ping('www.whatever-site-doing-the-ping.com');
?>
I ran the above script and got the "offline" result. I then replaced Google.com with Yahoo.com and got the same result. On the surface all appears to be fine, however, before I include this script in the program I need to insure it is correct. If someone could answer the following questions for me I would greatly appreciate it:
1) Is my interpretation correct and just happen to catch both engines offline?
2) Is the [ //Test ping: Goolge.com; ] there to let the engine know it is a test and have to be removed when the script is live?
3) Is my interpretation correct in assuming that the:
echo ping('www.whatever-site-doing-the-ping.com');
is correct?
4) Would the following line be correct to ping more than one search engine at a time or would I have to run the script for each desired engine?
ping('www.google.com', 'www.Yahoo.com', 'www.Ask.com', 'www.msn.com');
5) To ping a search engine is using the top level url (eg. www.google.com) proper or do you need to ping a specific page on the domain? If so does anyone have the proper pages for google.com, yahoo.com, ask.com and msn.com
Thank you for taking the time to read my post and appreciate any help you may be able to provide.
pete