Created
June 22, 2012 01:06
-
-
Save kijtra/2969635 to your computer and use it in GitHub Desktop.
[PHP] サイトマップ(sitemap.xml等)を各検索エンジンに一括送信する関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function sitemap_send($urls=NULL){ | |
if(empty($urls)){ | |
return NULL; | |
} | |
$pings=array( | |
'google'=>array( | |
'ping'=>'http://www.google.com/webmasters/sitemaps/ping?sitemap=', | |
'reg'=>'/successfully added/' | |
), | |
'bing'=>array( | |
'ping'=>'http://www.bing.com/webmaster/ping.aspx?siteMap=', | |
'reg'=>'/(ありがとうございました)/' | |
), | |
/* Not Active...? | |
'msn'=>array( | |
'ping'=>'http://webmaster.live.com/ping.aspx?siteMap', | |
'reg'=>'' | |
), | |
*/ | |
/* Need AppID | |
'yahoo'=>array( | |
'ping'=>'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=[appID]&url=', | |
'reg'=>'' | |
), | |
*/ | |
); | |
$urls=(is_array($urls)) ? $urls : array($urls); | |
$mh=curl_multi_init(); | |
$arr=array(); | |
foreach($urls as $url){ | |
if(empty($url) || is_array($url) || strpos($url,'http')!==0){ | |
continue; | |
} | |
$arr[$url]=array(); | |
foreach($pings as $key=>$val){ | |
$arr[$url][$key]=curl_init($val['ping'].urlencode($url)); | |
curl_setopt($arr[$url][$key],CURLOPT_HEADER,0); | |
curl_setopt($arr[$url][$key],CURLOPT_RETURNTRANSFER,1); | |
curl_multi_add_handle($mh,$arr[$url][$key]); | |
} | |
} | |
do{ | |
$status=curl_multi_exec($mh,$active); | |
}while($status===CURLM_CALL_MULTI_PERFORM || $active); | |
$results=array(); | |
foreach($arr as $url=>$sites){ | |
if(!is_array($sites)){ | |
continue; | |
} | |
$results[$url]=array(); | |
foreach($sites as $site=>$c){ | |
if(empty($c)){ | |
continue; | |
} | |
$content=curl_multi_getcontent($c); | |
curl_multi_remove_handle($mh,$c); | |
$results[$url][$site]=(!empty($content) && preg_match($pings[$site]['reg'],$content)); | |
} | |
} | |
curl_multi_close($mh); | |
return $results; | |
} | |
/* example | |
sitemap_send('http://example.com/sitemap.xml'); | |
OR | |
sitemap_send(array( 'http://example.com/sitemap.xml', 'http://example.com/sitemap2.xml' )); | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment