Ping Search Engines Function

ping_search_engines ( [ string $sitemap ] )

This function can be used to ping search engines when your sitemap changes. Yahoo has deprecated (and will discontinue) their ping service, so I took them out. If you know of any other search engines worth considering, be sure to share them with the rest of us in your comments.

$sitemap The sitemap that you want to ping to the search engines. The default is http://www.your-website.com/sitemap.xml
Returns An error if a ping was unsuccessful.
Example
ping_search_engines();
Click to Download the PHP Ping Search Engines Function

 Subscribe to our feed

ping_search_engines.php

<?php 
 
/* 
 *    author:		Kyle Gadd 
 *    documentation:	http://www.php-ease.com/functions/ping_search_engines.html 
 * 
 *    This program is free software: you can redistribute it and/or modify 
 *    it under the terms of the GNU General Public License as published by 
 *    the Free Software Foundation, either version 3 of the License, or 
 *    (at your option) any later version. 
 * 
 *    This program is distributed in the hope that it will be useful, 
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *    GNU General Public License for more details. 
 * 
 *    You should have received a copy of the GNU General Public License 
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */ 
 
function ping_search_engines ($sitemap='') { 
  if (empty($sitemap)) $sitemap = BASE_URL . 'sitemap.xml'; 
  $engines = array(); 
  $engines['www.google.com'] = '/webmasters/sitemaps/ping?sitemap=' . urlencode($sitemap); // google 
  $engines['submissions.ask.com'] = '/ping?sitemap=' . urlencode($sitemap); // ask 
  $engines['www.bing.com'] = '/webmaster/ping.aspx?sitemap=' . urlencode($sitemap); // bing 
  foreach ($engines as $host => $path) { 
    $fp = fsockopen($host, 80); 
    $send = "HEAD $path HTTP/1.1\r\n"; 
    $send .= "HOST: $host\r\n"; 
    $send .= "CONNECTION: Close\r\n\r\n"; 
    fwrite($fp, $send); 
    $http_response = fgets($fp, 128); 
    fclose($fp); 
    list($response, $code) = explode (' ', $http_response); 
    if ($code != 200) trigger_error ("{$host} ping was unsuccessful.<br />Code: {$code}<br />Response: {$response}"); 
  } 
} 
 
?>

comments powered by Disqus
Copyright © 2011 PHP-Ease.com - PHP Made Easy