PHP blog ping service code

  • 2020-05-12 02:22:29
  • OfStack

PHP ping service code is in the past I have written one class, however, there are a lot of friends and my friends say, see don't understand, that is written in the form of a class, can be directly on the code if not directly use row, today send 1 ping function that can directly use, hope to be of help, you also need to show 1 point is now ping is not so effective as it once was, because, baidu and gg may also join the other indicators, the new website ping can succeed, but not 1 is absolutely.
 
<?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 of notes </string></value></param> 
<param><value><string>//www.ofstack.com</string></value></param> 
<param><value><string>//www.ofstack.com/001</string></value></param> 
<param><value><string>//www.ofstack.com</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 failure "; 
} 
?> 

Related articles: