百度 Google Ping主动推送方法

  1. function ping($data){
  2. $server_url = array(
  3. 'baidu' => 'http://ping.baidu.com/ping/RPC2',
  4. // 'google' => 'http://blogsearch.google.com/ping/RPC2',
  5. //'bloglines' => 'http://www.bloglines.com/ping'
  6. );
  7. $xml = '
  8. weblogUpdates.extendedPing
  9. ' . $data['blog_name'] . '
  10. ' . $data['blog_home'] . '
  11. ' . $data['blog_url'] . '
  12. ' . $data['rss_url'] . '
  13. '
  14. $xml_baidu = '
  15. weblogUpdates.extendedPing
  16. ' . $data['blog_name'] . '
  17. ' . $data['blog_home'] . '
  18. ' . $data['blog_url'] . '
  19. ' . $data['rss_url'] . '
  20. '
  21. foreach
  22. ($server_url as $k => $s){
  23. $s = trim($s);
  24. if(!emptyempty($s)){
  25. $c = curl_init();
  26. $header = array(
  27. "Content-type: text/xml;charset=\\"utf-8\\"",
  28. "Accept: text/xml"
  29. );
  30. curl_setopt
  31. _array(
  32. $c,
  33. array(
  34. CURLOPT_URL => $s,
  35. CURLOPT_RETURNTRANSFER => true,
  36. CURLOPT_POST => true,
  37. CURLOPT_HTTPHEADER => $header,
  38. CURLOPT_POSTFIELDS => $k === 'baidu' ? $xml_baidu : $xml
  39. )
  40. );
  41. $content=curl_exec($c);
  42. var_dump($content);
  43. curl_close($c);
  44. }
  45. }
  46. }