Home Backend Development PHP Tutorial 百度实时推送api接口应用示例_PHP

百度实时推送api接口应用示例_PHP

May 31, 2016 pm 07:29 PM
api interface real time push Baidu

网站质量不错的网站可以在百度站长平台/数据提交/sitemap栏目下看到实时推送的功能, 目前这个工具是邀请开放, 百度的实时推送的api接口可以实时推送我们新发布的文章, 保证百度在第一时间收录.
 
百度站长平台 http://zhanzhang.baidu.com/


打开百度站长平台, 点开实时推送的添加新数据接口获得带token的api推送地址:
 
  http://ping.baidu.com/sitemap?site=www.yourdomain.com&resource_name=sitemap&access_token=xxxxxxx 
 

分享一段网友写的php实时推送代码: 

php 实时推送新发布的文章

socketopen方式推送sitemap

代码如下:


 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 = '';
           foreach($urls as $url){
               $xml .= '';
               $xml .= '';
               $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文档

代码如下:


 
    
        
            
                
                     200
                

            
        
     
    

状态码含义如下

200 无使用方式错误,需要进一步观察返回的内容是否正确
400 必选参数未提供
405 不支持的请求方式,我们只支持POST方式提交数据
411 HTTP头中缺少Content-Length字段
413 推送的数据过大,超过了10MB的限制
422 HTTP头中Content-Length声明的长度和实际发送的数据长度不一致
500 站长平台服务器内部错误
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to skip security warnings in Baidu How to skip security warnings in Baidu Feb 23, 2024 pm 10:34 PM

How to skip security warnings in Baidu? There are various security protection services in Baidu APP, but most friends don’t know how to skip security warnings. Next, the editor brings to users pictures and texts on how to skip security warnings in Baidu. Tutorial, interested users come and take a look! How to skip security warnings in Baidu 1. First open Baidu APP, enter the lower right corner of the main page, click [My], and click [Settings] in the upper right corner of the My area; 2. Then on the settings function page, select [Internet Security]; 3. Finally, on the Internet security interface, click [Website Security] to skip the complete warning.

How to use Baidu advanced search How to use Baidu advanced search Feb 22, 2024 am 11:09 AM

How to use Baidu Advanced Search Baidu search engine is currently one of the most commonly used search engines in China. It provides a wealth of search functions, one of which is advanced search. Advanced search can help users search for the information they need more accurately and improve search efficiency. So, how to use Baidu advanced search? The first step is to open the Baidu search engine homepage. First, we need to open Baidu’s official website, which is www.baidu.com. This is the entrance to Baidu search. In the second step, click the Advanced Search button. On the right side of the Baidu search box, there is

After 2 months, the humanoid robot Walker S can fold clothes After 2 months, the humanoid robot Walker S can fold clothes Apr 03, 2024 am 08:01 AM

Editor of Machine Power Report: Wu Xin The domestic version of the humanoid robot + large model team completed the operation task of complex flexible materials such as folding clothes for the first time. With the unveiling of Figure01, which integrates OpenAI's multi-modal large model, the related progress of domestic peers has been attracting attention. Just yesterday, UBTECH, China's "number one humanoid robot stock", released the first demo of the humanoid robot WalkerS that is deeply integrated with Baidu Wenxin's large model, showing some interesting new features. Now, WalkerS, blessed by Baidu Wenxin’s large model capabilities, looks like this. Like Figure01, WalkerS does not move around, but stands behind a desk to complete a series of tasks. It can follow human commands and fold clothes

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

How to disable Baidu incognito mode How to disable Baidu incognito mode Feb 29, 2024 pm 03:40 PM

Baidu Incognito Mode is a privacy protection feature that allows users to use Baidu search or other services without leaving any personal information or browsing history. For some users, they may want to turn off incognito mode so that they can keep their search history or browsing history. So how to release Baidu incognito mode? Friends who are still unclear, don’t worry. Next, the editor will bring you a method to remove the incognito browsing mode. You can follow the steps below. How to release Baidu incognito mode 1. Click the [Baidu] icon on the desktop to open the Baidu APP. 2. Search for something and enter the search results page. 3. Click [≡] at the bottom of the page. 4. Find "Multi-Window" in the pop-up window and click to enter. 5. Turn on/off "Incognito"

What are the main types of api interfaces? What are the main types of api interfaces? Apr 23, 2024 pm 01:57 PM

API interface types are rich and diverse, including RESTful API, SOAP API, GraphQL API, etc. RESTful API communicates through the HTTP protocol, with a simple and efficient design, which is the current mainstream Web API design style. SOAP API is based on XML, focuses on cross-language and platform interoperability, and is mostly used in large enterprises and government agencies. GraphQL API is a new query language and runtime environment that supports flexible data query and response.

Introduction to how to obtain Baidu Xiyang Shells Introduction to how to obtain Baidu Xiyang Shells Mar 28, 2024 am 09:11 AM

There are many users in Xirang who don’t know where the shells are and how to get them. Some players have been searching for several hours but still can’t find them. Below, the editor will introduce how to obtain Baidu Xirang shells. Come and take a look. . How to get Baidu Xirang Shell 1. First we need to come to the community, and then come to the location in the picture below. 2. Select the destination here and choose to enter the 188th floor. 3. After entering the 188th floor, you will see this prompt when walking around. Just click I Got It. 4. The location of the shell may be a little difficult to find. Just behind the 188 elevator, there is a small glowing dot that is the shell. 5. You need to use a VR controller to pick up shells. Just click on the shell. Redemption method 1. First click the "Settings" icon in the upper right corner of the page and select "

Baidu Apollo releases Apollo ADFM, the world's first large model that supports L4 autonomous driving Baidu Apollo releases Apollo ADFM, the world's first large model that supports L4 autonomous driving Jun 04, 2024 pm 08:01 PM

On May 15, Baidu Apollo held Apollo Day 2024 in Wuhan Baidu Luobo Automobile Robot Zhixing Valley, comprehensively demonstrating Baidu's major progress in autonomous driving over the past ten years, bringing technological leaps based on large models and a new definition of passenger safety. With the world's largest autonomous vehicle operation network, Baidu has made autonomous driving safer than human driving. Thanks to this, safer, more comfortable, green and low-carbon travel methods are turning from ideal to reality. Wang Yunpeng, vice president of Baidu Group and president of the Intelligent Driving Business Group, said on the spot: "Our original intention to build autonomous vehicles is to satisfy people's growing yearning for better travel. People's satisfaction is our driving force. Because safety, So beautiful, we are happy to see

See all articles