When using the method access automatically ping to Baidu, my method is to generate the cache, update the cache when automatically ping Baidu, return the result of 0 to indicate success.
Copy Code code as follows:
$pingarcurl = ' http://'. $_server[' http_host '].$_server[' Request_uri '];
$arcping = new Ping (' cloud-dwelling community ', $pingarcurl, Get_domain (), ' http://www.jb51.net ');
$arcping->pingbaidu ();
Copy Code code as follows:
Class ping{
private$title;//Blog Name
private$hosturl;//Blog Home Address
private$arturl;//new article Address
private$rssurl;//Blog RSS Address
private$baiduxml;//Baidu XML Structure
private$baidurpc;//Baidu XML Address
Publicfunction__construct ($title, $arturl, $hosturl, $rssurl)
{
if (Empty ($title) | | Empty ($arturl))
Returnfalse;
$this->title= $title;
$this->hosturl= $hosturl;
$this->rssurl= $rssurl;
$this->arturl= $arturl;
$this->baidurpc= ' http://ping.baidu.com/ping/RPC2 ';
$this->baiduxml= ' <?xmlversion=\ ' 1.0\ "encoding=\" utf-8\ "?>";
$this->baiduxml.= ' <methodCall> ';
$this->baiduxml.= ' <methodName>weblogUpdates.extendedPing</methodName> ';
$this->baiduxml.= ' <params> ';
$this->baiduxml.= ' <param><value><string> '. $this->hosturl. ' </string></value></param> ';
$this->baiduxml.= ' <param><value><string> '. $this->title. ' </string></value></param> ';
$this->baiduxml.= ' <param><value><string> '. $this->arturl. ' </string></value></param> ';
$this->baiduxml.= ' <param><value><string> '. $this->rssurl. ' </string></value></param> ';
$this->baiduxml.= ' </params> ';
$this->baiduxml.= ' </methodCall> ';
}
Publicfunctionpingbaidu ()
{
$ch =curl_init ();
$headers =array (
' User-agent:request ',
' Host:ping.baidu.com ',
' Content-type:text/xml ',
);
curl_setopt ($ch, Curlopt_url, $this->baidurpc);
curl_setopt ($ch, curlopt_header,1);
curl_setopt ($ch, curlopt_returntransfer,1);
curl_setopt ($ch, curlopt_post,1);
curl_setopt ($ch, Curlopt_httpheader, $headers);
curl_setopt ($ch, Curlopt_postfields, $this->baiduxml);
$res =curl_exec ($ch);
Curl_close ($ch);
Return$res;
Return (Strpos ($res, "<int>0</int>")) True:false;
}
}
Functionget_domain ()
{
/* Agreement * *
$protocol = ' http://';
/* Domain name or IP address * *
if (Isset ($_server[' http_x_forwarded_host ')) {
$host =$_server[' Http_x_forwarded_host '];
}elseif (Isset ($_server[' http_host ')) {
$host =$_server[' Http_host '];
}else{
/* Port * *
if (Isset ($_server[' Server_port ')) {
$port = ': ' $_server[' server_port '];
if (': ' = = $port & ' http://' = $protocol) | | (': 443 ' = $port & ' https://' = $protocol)) {
$port = ';
}
}else{
$port = ';
}
if (Isset ($_server[' server_name ')) {
$host =$_server[' server_name ']. $port;
}elseif (Isset ($_server[' server_addr ')) {
$host =$_server[' server_addr ']. $port;
}
}
Return$protocol. $host;
}
$arc =newping (' website title ', ' Updated URL address ', ' website domain name ', ' RSS address ');
$arc =newping (' title of your site ', Get_arcurl ($id), Get_domain (), ' http://www.abc.com/rss.php ');
Echo$arc->pingbaidu ();
The return result of 0 indicates success.