Ping your sitemap
What if you have a sitemap.xml file on your server, and you want to automate the pinging of search engines like google, yahoo, ask and moreover (from what I understand, the sitemaps service for MSN)? If you have a CMS such as Drupal or WordPress, it will automatically ping, or you can ping with PHP XML-RPC plugins.I couldn’t find an easy way to simply automate the pinging of my sitemap file with PHP, so I cobbled together my own solution. The only thing you need to do to make this thing work is to replace all the instances of www.mydomain.com with the name of your actual name, and specify the variable ‘$sitemapname’ (i.e. sitemap.xml). So, give the following a try and tell me what you think!echo "<table border=1><tr><th>Pings</th></tr>"; //lets setup a table that will show the status of our pingsecho "<tr><td>";$url_xml = $sitemapname;function pingGoogleSitemaps( $url_xml ){$status = 0;$google = 'www.google.com';if( $fp=@fsockopen($google, 80)){$req = 'GET /webmasters/sitemaps/ping?sitemap=' .urlencode( $url_xml ) . " HTTP/1.1\r\n" ."Host: $google\r\n" ."User-Agent: Mozilla/5.0 (compatible; " .PHP_OS . ") PHP/" . PHP_VERSION . "\r\n" ."Connection: Close\r\n\r\n";fwrite( $fp, $req);while( !feof($fp)){if( @preg_match('~^HTTP/\d\.\d (\d+)~i', fgets($fp, 128), $m)){$status = intval( $m[1] );break;}}fclose( $fp );}return( $status );}if(200 === ($status=pingGoogleSitemaps(’http://www.yourdomain.com/sitemap.xml’))){echo “Ping to Google Sitemaps successful.\r\n\r\nStatus code: $status”;}else{echo “Cannot ping/connect to Google Sitemaps.\r\n\r\nStatus code: $status”;}// end the script.echo “</td></tr>”;echo “<tr><td>”;function pingAsk( $url_xml ){$status = 0;$ask = ’submissions.ask.com’;if( $fp=@fsockopen($ask, 80) ){$req = ‘GET /ping?sitemap=’ .urlencode( $url_xml ) . ” HTTP/1.1\r\n” .”Host: $ask\r\n” .”User-Agent: Mozilla/5.0 (compatible; ” .PHP_OS . “) PHP/” . PHP_VERSION . “\r\n” .”Connection: Close\r\n\r\n”;fwrite( $fp, $req );while( !feof($fp) ){if( @preg_match(’~^HTTP/\d\.\d (\d+)~i’, fgets($fp, 128), $m) ){$status = intval( $m[1] );break;}}fclose( $fp );}return( $status );}if( 200 === ($status=pingAsk(’http://www.yourdomain.com/sitemap.xml’)) ){echo “Ping to Ask Sitemaps successful.\r\n\r\nStatus code: $status”;}else{echo “Cannot ping/connect to Ask.\r\n\r\nStatus code: $status”;}// end the script.echo “</td></tr>”;echo “<tr><td>”;function pingYahoo( $url_xml ){$status = 0;$yahoo = ’search.yahooapis.com’;if( $fp=@fsockopen($yahoo, 80) ){$req = ‘GET /SiteExplorerService/V1/ping?sitemap=’ .urlencode( $url_xml ) . ” HTTP/1.1\r\n” .”Host: $yahoo\r\n” .”User-Agent: Mozilla/5.0 (compatible; ” .PHP_OS . “) PHP/” . PHP_VERSION . “\r\n” .”Connection: Close\r\n\r\n”;fwrite( $fp, $req );while( !feof($fp) ){if( @preg_match(’~^HTTP/\d\.\d (\d+)~i’, fgets($fp, 128), $m) ){$status = intval( $m[1] );break;}}fclose( $fp );}return( $status );}if( 200 === ($status=pingYahoo(’http://www.yourdomain.com/sitemap.xml’)) ){echo “Ping to Yahoo Sitemaps successful.\r\n\r\nStatus code: $status”;}else{echo “Cannot ping/connect to Yahoo.\r\n\r\nStatus code: $status”;}// end the script.echo “</td></tr>”;echo “<tr><td>”;function pingMoreover( $url_xml ){$status = 0;$moreover = ‘api.moreover.com’;if( $fp=@fsockopen($moreover, 80) ){$req = ‘GET /ping?u=’ .urlencode( $url_xml ) . ” HTTP/1.1\r\n” .”Host: $moreover\r\n” .”User-Agent: Mozilla/5.0 (compatible; ” .PHP_OS . “) PHP/” . PHP_VERSION . “\r\n” .”Connection: Close\r\n\r\n”;fwrite( $fp, $req );while( !feof($fp) ){if( @preg_match(’~^HTTP/\d\.\d (\d+)~i’, fgets($fp, 128), $m) ){$status = intval( $m[1] );break;}}fclose( $fp );}return( $status );}if( 200 === ($status=pingMoreover(’http://www.yourdomain.com/sitemap.xml’)) ){echo “Ping to Moreover Sitemaps successful.\r\n\r\nStatus code: $status”;}else{echo “Cannot ping/connect to Moreover.\r\n\r\nStatus code: $status”;}// end the script.echo “</td></tr>”;echo “</table>”;?>























