This article mainly introduces the application example of Baidu real-time push api interface, which is very practical, if you have any need, please refer to the website with good quality. you can see the real-time push function under the Baidu webmaster platform/data submission/sitemap column. Currently, this tool is open to users, the api of Baidu's real-time push can push our new articles in real time to ensure that Baidu is included immediately.
Baidu webmaster platform http://zhanzhang.baidu.com/
Open the Baidu webmaster platform and click the Add data interface of real-time push to get the api push address with token:
Http://ping.baidu.com/sitemap? Site = www.yourdomain.com & resource_name = sitemap & access_token = xxxxxxx
Share a piece of php real-time push code written by a netizen:
Php pushes new articles in real time
Push sitemap in socketopen mode
The code is as follows:
Function sitemap_ping_baidu ($ urls ){
$ Baidu_ping_url = 'ping .baidu.com ';
$ Get = '/sitemap? Site = www.yourdomain.com & resource_name = sitemap & access_token = xxxxxxx ';
$ Port = 80;
If ($ io = fsockopen ($ baidu_ping_url, $ port, $ errno, $ errstr, 50 ))! = False ){
$ Send = "POST $ 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. = 'User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0) '. "rn ";
$ Xml = '<? Xml version = "1.0" encoding = "UTF-8"?> ';
Foreach ($ urls as $ url ){
$ Xml. =' ';
$ Xml. =' '.$url.' ';
$ Xml. =' '. Date ('Y-m-D ').' ';
$ Xml. =' Monthly ';
$ Xml. =' 0.8 ';
$ Xml. =' ';
}
$ Xml. =' ';
$ Send. = 'content-Length: '. strlen ($ xml). "rn ";
$ Send. = "Connection: Closernrn ";
$ Send. = $ xml. "rn ";
Fputs ($ io, $ send );
$ Return = '';
While (! Feof ($ io ))
{
$ Return. = fread ($ io, 4096 );
}
Return $ return;
} Else {
Return false;
}
}
$ Return = sitemap_ping_baidu (array ('http: // www.yourdomain.com/a.php? Id = 1 '));
Xml document returned by Baidu after push
The code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
200
The status code is as follows:
200 |
No usage error. you need to check whether the returned content is correct. |
400 |
Required parameter not provided |
405 |
Unsupported request method. we only support data submission in POST mode. |
411 |
The Content-Length field is missing in the HTTP header |
413 |
The pushed data is too large and exceeds the limit of 10 MB. |
422 |
The Length of the Content-Length statement in the HTTP header is inconsistent with the actual Length of the sent data. |
500 |
Internal Server Error of webmaster platform |