PHP Ping Service Code In fact I've written a class before, however, there are a lot of friends add my friend said, see not quite understand, that is written in the form of a class, may be directly put into the code directly with not too good, today can be directly used ping function, I hope to help you, Also need to note that the current ping is not as useful as before, because, Baidu and GG may have added other indicators, the new site ping can be successful, but not necessarily hundred included.
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>web Development Notes </string></value></param>
<param><value><string>http://www.jb51.net</string></value></param>
<param><value><string>http://www.jb51.net/001</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";
}
?>