Baidu Real-time Push API Interface application Example _php instance

Source: Internet
Author: User

Website Quality good site can be in the Baidu Webmaster Platform/Data submitted/sitemap column to see real-time push the function, the current tool is invited to open, Baidu real-time push API interface can be real-time push to send us new articles, to ensure that Baidu in the first time included.

Baidu Webmaster Platform http://zhanzhang.baidu.com/


Open Baidu Webmaster Platform, point open real-time push add new data interface get with token API push address:

Http://ping.baidu.com/sitemap?site=www.yourdomain.com&resource_name=sitemap&access_token=xxxxxxx

Share a user wrote PHP real-time push code:

PHP real-time push for new published articles

Socketopen Way to push Sitemap

Copy Code code 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,)!== 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 '?><urlset> ';
foreach ($urls as $url) {
$xml. = ' <url> ';
$xml. = ' <loc><! [cdata['. $url. ']] ></loc> ';
$xml. = ' <lastmod> '. Date (' y-m-d '). </lastmod> ';
$xml. = ' <changefreq>monthly</changefreq> ';
$xml. = ' <priority>0.8</priority> ';
$xml. = ' </url> ';
}
$xml. = ' </urlset> ';

$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 '));


The XML document that Baidu will return after push send

Copy Code code as follows:

<?xml version= "1.0" encoding= "UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<int>200</int>
</value>
<param>
</params>
</methodResponse>

The status code means the following

200 No usage error, need to see if the returned content is correct
400 Required parameter not provided
405 Unsupported request method, we only support post method submission data
411 Missing content-length field in HTTP header
413 The data pushed is too large to exceed the 10MB limit.
422 The length of the Content-length declaration in the HTTP header is inconsistent with the actual length of the data being sent
500 Webmaster Platform Server Internal Error

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.