This article mainly introduces the use of Baidu ping Service Code instances in php. Baidu ping service can accelerate the indexing of its own website, which is generally called when the article is published. If you need it, refer to the following code example:
<? Phpfunction postUrl ($ url, $ postvar) {$ ch = curl_init (); $ headers = array ("POST ". $ url. "HTTP/1.0", "Content-type: text/xml; charset = \" gb2312 \ "", "Accept: text/xml", "Content-length :". strlen ($ postvar); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POST, 1 ); curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ headers); curl_setopt ($ ch, CURLOPT_POSTFIELD S, $ postvar); $ res = curl_exec ($ ch); curl_close ($ ch); return $ res ;}$ baiduXML = "<? Xml version = \ "1.0 \" encoding = \ "gb2312 \"?>
WeblogUpdates. extendedPing
Yurendu
Http://www.php.net
Http://www.php.net/read.php? Tid-96.html
Http://www.php.net
"; $ Res = postUrl ('HTTP: // ping.baidu.com/ping/RPC2', $ baiduXML); if (strpos ($ res ,"
0
") {Echo" PING succeeded ";}else {echo" PING failed ";}?>