Manually add a ping service to a website for PHP

Source: Internet
Author: User
Manually add a ping service to a Web site for PHP

Transferred from: Http://lwxshow.com/php-setting-ping-manual-google-baidu

?

To manually add a ping service

"1" Google's ping service for PHP implementation

A detailed introduction to RPC can be in the Wikipedia, Google Ping service standard:
RPC Endpoint: http://blogsearch.google.com/ping/RPC2
Call Method Name: weblogupdates.extendedping
Parameters: (should be delivered in the same order as listed below)
Station name
Site URL
Need to check for updated page URLs
The 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 delimited.
The first thing to do is write a curl function to post the Google RPC endpoint:

Copy CodeThe code is 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 is written, the rest is to assemble the data sent according to Google's XML-RPC standard, detailed request examples can refer to the official case, click here.
My code, for example, is written like this:

Copy CodeThe code is as follows:

$googleXML = <<

Weblogupdates.extendedping


Ping service PHP Implementation method, so that the site is quickly included


Http://s.jb51.net


Http://s.jb51.net/archives/47.html


Http://s.jb51.net/feed



END;
$res = PostURL (' http://blogsearch.google.com/ping/rpc2′, $googleXML);
The following is the decision to return success (based on the interface description of Google ping)
if (Strpos ($res, " 0 "))
echo "Ping succeeded";
Else
echo "Ping failed";

OK, this can be a simple implementation of the Google Ping service. This function can be implemented according to the Code self-modification.
"* *" Baidu's Ping Service PHP implementation (this title true dt)
Baidu's Ping service XML code is different from Google, Baidu will always have its own characteristics:
Introduction under the Baidu Blog Ping Service, Baidu Blog Ping Service Detailed introduction, please visit: http://www.baidu.com/search/blogsearch_help.html#n7.
Baidu's Ping service is based on the XML-RPC standard protocol, but unlike the Google Ping service is the Baidu Ping sent the XML format is different, we need to use the string node package content.
For example:

Copy CodeThe code is as follows:



Weblogupdates.extendedping


Ping service PHP Implementation method, so that the site is quickly included


http://s.jb51.net/


Http://s.jb51.net/archives/47.html


Http://s.jb51.net/feed


According to the above mentioned Google interface, we just change the submitted XML content can, of course, Baidu Ping service return judgment is different from Google, can also make corresponding changes,
Here's the code for PHP:

Copy CodeThe code is as follows:

$baiduXML = <<

Weblogupdates.extendedping

Ping service PHP Implementation method, so that the site is quickly included
Http://s.jb51.net
Http://s.jb51.net/archives/47.html
Http://s.jb51.net/feed


EOT;
$res = PostURL (' http://ping.baidu.com/ping/rpc2′, $baiduXML);
The following is the decision to return success (according to the interface description of Baidu Ping)
if (Strpos ($res, " 0 "))
echo "Ping succeeded";
Else
echo "Ping failed";

The above code can implement the PHP ping service. Well, the following to provide you with a Baidu Ping service code, no way who let him so unique that?

Copy CodeThe code is as follows:

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 = "

Weblogupdates.extendedping

Home of the script
Http://www.jb51.net
Http://www.jb51.net/a/15222.html
Http://www.jb51.net

";
$res = PostURL (' http://ping.baidu.com/ping/rpc2′, $baiduXML);
if (Strpos ($res, " 0 ") )
{
echo "Ping succeeded";
}
Else
{
echo "Ping failed";
}
?>

  • Related Article

    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.