Baidu Ping method using the example automatically ping Baidu _php instance

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.