This article mainly introduced the baidu real-time push API interface application examples, very practical, friends in need can be under reference

good quality of the site can be found in baidu station platform under/data submission/sitemap see the function of real-time delivery, this tool is currently open invitation, baidu's real-time push API interface can push our time for the new post, baidu included in the first time.
Baidu station platform

open baidu station platform, it opens at real-time push to add new data interface to get token API push address: &resource_name=sitemap&access _token=xxxxxxx 

share a net friend PHP code: real-time push  

PHP live post new article

socketopen way to push a sitemap

code is as follows:

  The function sitemap_ping_baidu ($urls) {
                $_get='/sitemap ? &resource_name=sitemap&access _token=XXXXXXX ';
                If (($IO=fsockopen ($baidu_ping_url, $port, $errno, $errstr, 50))!==false)   {
                        $send="POST $a get HTTP/1.1". "rn";
                        $send.='Accept: */*'. "rn";
                        $send.='cache-control: no - Cache. "rn";
                    $send.='Host:'. $baidu_ping_url. "rn";
                    $send.='Pragma: no cache -'. "rn";
                   //$send.="Referer: http://". $url. $get. "rn";
                   //$send.='the user-agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)'. "rn";
                    $XML='<The ? The XML version="1.0" encoding="utf-8" ? ><Urlset> ';
                    The foreach ($urls as $url) {
                            $XML.='<Url> ';
                            $XML.='<Loc> <! [CDATA ['. $url.]] ></loc> ';
                            $XML.='<Lastmod> 'date (' Y -m - d'). '</lastmod> ';
                            $XML.='<Changefreq> Monthly ';
                            $XML.='<Priority> 0.8 </priority> ';
                            $XML.='</url> ';
                    $XML.='</urlset> ';

                    $send.='Content - Length:' the strlen ($XML). "rn";
                    $send.="Connection: Closernrn";

                    $send.=$XML. "rn";

                    Fputs ($IO, $send);

                    $return=' ';
                    While (! Feof ($I/o))
                            $return.=fread ($IO, 4096);
                    Return $return;
            } else {
                    Return false;
$return=sitemap_ping_baidu (array (' '));

after push baidu will return an XML document

code is as follows:

  <The ? The XML version="1.0" encoding="utf-8" ? >
                                        <Int> 200 </int>

status code meaning below



200 no use error, need to further observe the content of the return is correct
400 will be selected parameters did not provide a
405 does not support the request of the way, we only support the POST way to submit data
411 HTTP header lacks the Content - Length field
413 push data is too large, more than 10 MB limit
422 HTTP header Content - Length statement do not match the Length of the Length and the actual data
500 adsense platform server internal error

you might be interested in the article:

  • baidu map API application with geographical location information (js)
  • Java calls baidu location API service access location example
  • javascript use baidu map API and HTML 5 features for browser location
  • js calls baidu map API and dot on the map to add annotation
  • baidu map API application of the user's location

This concludes the body part