Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Baidu automatic ping

Shulou Source: shulou.com Published: 2022-06-03 07:45:47 09月22日 Update

This article introduces the relevant knowledge of "how to use Baidu automatic ping". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Use method access when automatically ping to Baidu, my method is to generate cache, update cache when automatically ping Baidu, return a result of 0 indicates success.

The copy code is as follows:

$pingarcurl=' http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

$arcping = new Ping ('', $pingarcurl,get_domain (), 'https://www.jb51.net');

$arcping- > pingbaidu ()

The copy code is as follows:

Class ping {

Private$title;// blog name

Home address of private$hosturl;// blog

Private$arturl;// new post 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=''

$this- > baiduXML.=''

$this- > baiduXML.='weblogUpdates.extendedPing'

$this- > baiduXML.=''

$this- > baiduXML.=''.$this- > hosturl.''

$this- > baiduXML.=''.$this- > title.''

$this- > baiduXML.=''.$this- > arturl.''

$this- > baiduXML.=''.$this- > rssurl.''

$this- > baiduXML.=''

$this- > baiduXML.=''

}

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, "0")? 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 ((': 80 million dollars) 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',get_arcurl of your website ($id), get_domain (),' http://www.abc.com/rss.php');

/ / echo$arc- > pingbaidu ()

/ / A result of 0 indicates success.

This is the end of the content of "how to use Baidu automatic ping". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Address code website blog success content domain name article method time more knowledge result cache update utility achievement next use method name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Linux MySQL vpn