Ping service PHP Implementation method, let the site quickly be included _php tips

Source: Internet
Author: User
Tags curl
This article goes on to talk about this ping service problem by summarizing and summarizing the following information:
"1" Ping service address manually:
Baidu Address: http://ping.baidu.com/ping.html
Google (google) address: http://blogsearch.google.com/ping
Feedsky (Fei-pass) Address: http://ping.feedsky.com/ping.html
Qihoo (Odd Tiger) address: http://so.blog.qihoo.com/pingblog.html
Iask (love to ask) address: http://blog.iask.com/ping.php
"2" Auto Ping Service Application Programming Interface (API):
Google (google): http://blogsearch.google.com/ping/RPC2
Feedburner:http://ping.feedburner.com
Feedsky (Flying pass): http://www.feedsky.com/api/RPC2
feedster:http://api.feedster.com/ping.php
Iask (Love to ask): Http://blog.iask.com/RPC2
Qihoo (Odd Tiger): http://ping.blog.qikoo.com/rpc2.php
Fresh Fruit: http://www.xianguo.com/xmlrpc/ping.php
Catch shrimp: http://www.zhuaxia.com/rpc/server.php
Blogdigger:http://www.blogdigger.com/rpc2
blo.gs:http://ping.blo.gs/
icerockethttp://rpc.icerocket.com:10080/
Moreover:http://api.moreover.com/rpc2
newsgator:http://rpc.newsgator.com/
syndic8:http://www.syndic8.com/xmlrpc.php
Weblogs:http://rpc.weblogs.com/rpc2
weblogalot:http://ping.weblogalot.com/rpc.php
The above, including the previous text of the ping service, some I tried to use some of the bad, to use those who look at the situation depends. This oneself according to the network environment and so on own test, suitable is the best, did not recommend.
OK, so many of the above, the following is the focus, that is, how to achieve ping services, WordPress can be implemented through the background, the other that? What if there's no ping service blogging program or something? According to what has been known, the blog system easy to use the WordPress with ping function, there is no doubt that the ASP class Z-blog seemingly can be implemented through plug-ins to achieve this function. Other blogging systems? The others? No other, my choice is only WordPress, no other, as long as the only. Oh, no kidding. The following is the question of PHP to implement Ping service, this is for others do not support the ping function of the site or system, and so on, you can develop an interface to achieve. For example, two of dedecms development can be, there are a lot of recent research on this project.
Need to say is Baidu's Ping and Google's submission format is different, the following simple said, respectively to Baidu and Google to do an introduction, the first introduction is Google (why not Baidu, OK?) Don't be so tangled, there will be ... ):
"*1" Google's ping service PHP implementation
Detailed description of RPC can go to Wikipedia, Google Ping service standards:
RPC Endpoint: http://blogsearch.google.com/ping/RPC2
Call Method Name: weblogupdates.extendedping
Parameters: (should be routed in the same order as listed below)
Station Roll Call
Site URL
Need to check the updated page URL
URL of the corresponding RSS, RDF, or Atom seed
Optional: the category name (or label) of the page content. You can specify multiple values, with ' | ' Characters are separated.
First, write a curl function to post Google's RPC endpoint:
Copy Code code as follows:

function PostURL ($url, $postvar) {
$ch = Curl_init ();
$headers = Array (
"POST". $url. " Http/1.0″,
"Content-type:text/xml;charset=\" utf-8\ "",
"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_postfields, $postvar);
$res = curl_exec ($ch);
Curl_close ($ch);
return $res;
}

After the main curl has been written, the rest is to be based on Google's XML-RPC standard to assemble the data sent, detailed request examples can refer to the official case, click here.
For example, my code is written like this:
Copy Code code as follows:

$googleXML = <<<end
<?xml version= "1.0″?>
<methodCall>
<methodName>weblogUpdates.extendedPing</methodName>
<params>
<param>
<value>ping Service PHP Implementation method, so that the site is indexed quickly </value>
</param>
<param>
<value>http://s.jb51.net</value>
</param>
<param>
<value>http://s.jb51.net/archives/47.html</value>
</param>
<param>
<value>http://s.jb51.net/feed</value>
</param>
</params>
</methodCall>
End;
$res = PostURL (' http://blogsearch.google.com/ping/rpc2′, $googleXML);
Here is the decision to return success (according to the Google Ping Interface description)
if (Strpos ($res, "<boolean>0</boolean>"))
echo "Ping successful";
Else
echo "Ping failed";

OK, this can be simple to achieve the Google Ping service. This functionality can be implemented by modifying the code itself.
"*2" Baidu Ping Service of the implementation of PHP (this title really dt)
Baidu's Ping service XML code is different from Google, Baidu will always have its own characteristics:
Under the introduction of Baidu blog Ping Service, Baidu Blog Ping Service Detailed introduction, please go: http://www.baidu.com/search/blogsearch_help.html#n7.
Baidu's Ping service is also based on the XML-RPC standard protocol, but with the Google Ping service is different from the Baidu Ping sent by the different format, we need to use string node parcel content.
For example:
Copy Code code as follows:

<?xml version= "1.0″encoding=" utf-8″?>
<methodCall>
<methodName>weblogUpdates.extendedPing</methodName>
<params>
<param>
<value><string>ping Service PHP Implementation method, so that the site is indexed quickly </string></value>
</param>
<param>
<value><string>http://s.jb51.net/</string></value>
</param>
<param>
<value><string>http://s.jb51.net/archives/47.html</string></value>
</param>
<param>
<value><string>http://s.jb51.net/feed</string></value>
</param>
</params>
</methodCall>

According to the Google interface mentioned above, we just change the submission of the XML content can, of course, Baidu Ping service to return the judgment is different from Google, you can make the corresponding changes,
Here is the code for PHP:
Copy code code as follows:

$baiduXML = <<<eot
<?xml version= "1.0″encoding=" utf-8″?>
<methodCall>
<methodName>weblogUpdates.extendedPing</methodName>
<params>
<param><value><string>ping Service PHP Implementation method, so that the site is indexed quickly </string></value></param>
<param><value><string>http://s.jb51.net</string></value></param>
<param><value><string>http://s.jb51.net/archives/47.html</string></value></ Param>
<param><value><string>http://s.jb51.net/feed</string></value></param>
</params>
</methodCall>
EOT;
$res = PostURL (' http://ping.baidu.com/ping/rpc2′, $baiduXML);
The following is the decision to return success (according to Baidu Ping Interface description)
if (Strpos ($res, "<int>0</int>"))
echo "Ping successful";
Else
echo "Ping failed";

The code above will enable you to ping the PHP service. Well, the following to provide you with a Baidu Ping service code, no way who let him so unique that?
Copy Code code as follows:

<?php
function 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_postfields, $postvar);
$res = curl_exec ($ch);
Curl_close ($ch);
return $res;
}
$baiduXML = "<?xml version=\" 1.0\ "encoding=\" gb2312\ "?>"
<methodCall>
<methodName>weblogUpdates.extendedPing</methodName>
<params>
<param><value><string> Cloud-dwelling community </string></value></param>
<param><value><string>http://www.jb51.net</string></value></param>
<param><value><string>http://www.jb51.net/a/15222.html</string></value></ Param>
<param><value><string>http://www.jb51.net</string></value></param>
</params>
</methodCall> ";
$res = PostURL (' http://ping.baidu.com/ping/rpc2′, $baiduXML);
if (Strpos ($res, "<int>0</int>"))
{
echo "Ping successful";
}
Else
{
echo "Ping failed";
}
?>

This article is very dt let me waste a draft of N to write, and then found that need to get a code plug-in to WP equipment. The problem of the code is really very tangled, there is the Chinese people's WP theme does not support paging, this let me very dt, said half a day, DT is what? I don't know......

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.