Heim > php教程 > php手册 > Hauptteil

Ping服务的php实现方法,让网站快速被收录

WBOY
Freigeben: 2016-06-06 20:39:58
Original
948 Leute haben es durchsucht

这篇博文继续说说这个ping服务的问题,首先归纳和总结以下资料

这篇文章继续说说这个ping服务的问题,首先归纳和总结以下资料:
【1】手动Ping服务地址:
Baidu(百度)地址: http://ping.baidu.com/ping.html
Google(谷歌)地址:http://blogsearch.google.com/ping
Feedsky(飞递)地址:http://ping.feedsky.com/ping.html
Qihoo(奇虎)地址:http://so.blog.qihoo.com/pingblog.html
IASK(爱问)地址:http://blog.iask.com/ping.php
【2】自动Ping 服务应用编程接口(API):
Google(谷歌):http://blogsearch.google.com/ping/RPC2
Feedburner:http://ping.feedburner.com
Feedsky(飞递):http://www.feedsky.com/api/RPC2
Feedster:http://api.feedster.com/ping.php
IASK(爱问):http://blog.iask.com/RPC2
Qihoo(奇虎):http://ping.blog.qikoo.com/rpc2.php
鲜果:http://www.xianguo.com/xmlrpc/ping.php
抓虾: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
上面提供的,包括前文说的ping服务,有些我试了好用 有些不好用,要用那些那个看情况而定。这个自己根据网络环境等自行测试下,适合的就是最好的,没有推荐。
好吧,说了那么多上面的,下面的是重点,也就是如何实现ping服务,wordpress是可以通过后台实现的,其他的那?比如没有ping服务功能的博客程序什么的怎么办?据纷纭所知道的,博客系统中好用的WORDPRESS自带PING功能,毋庸置疑,ASP类的Z-BLOG貌似可以通过插件实现这个功能。其他的博客系统?其他的?没有其他,我的选择唯有wordpress,没有其他,只要唯一。呵呵,不开玩笑了。下面说下php来实现ping的服务的问题,这个针对其他不支持ping功能的网站或者系统之类的,大家可以自行开发个接口实现。比如DEDECMS的二次开发就可以,纷纭最近在研究这个项目。
需要说的是百度的ping和谷歌的提交格式是不同的,下面简单的说说,分别给百度和谷歌做个介绍,首先介绍的是谷歌(为啥不是百度,OK?别那么纠结,会有的……):
【*1】谷歌的ping服务的php的实现
关于RPC的详细介绍可以移步维基百科,谷歌ping服务的标准:
RPC端点: http://blogsearch.google.com/ping/RPC2
调用方法名: weblogUpdates.extendedPing
参数: (应按照如下所列的相同顺序传送)
站点名
站点URL
需要检查更新的页面URL
相应的RSS、RDF或Atom种子的URL
可选:页面内容的分类名称(或标签)。您可以指定多个值,之间用'|'字符进行分隔。
首先要写一个CURL的函数,来POST谷歌的RPC端点:
代码如下:
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;
}

主要的curl写好了之后,剩下就是要根据谷歌的XML-RPC标准组装发送的数据了,详细的请求例子可以参考官方案例,点这里。
例如我的代码是这样写的:
代码如下:
$googleXML =

weblogUpdates.extendedPing


Ping服务的php实现方法,让网站快速被收录


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);
//下面是返回成功与否的判断(根据谷歌ping的接口说明)
if (strpos($res, "0"))
echo "PING成功";
else
echo "PING失败";

OK,这个就可以简单的实现谷歌的PING服务了。可以根据代码自行修改实现这个功能。
【*2】百度的ping服务的php的实现(这个标题真DT)
百度的ping服务xml代码是跟谷歌不同的,百度总是会有自己的特点:
介绍下百度博客ping服务,百度博客Ping服务的详细介绍,请移步:http://www.baidu.com/search/blogsearch_help.html#n7。
百度的ping服务也是基于XML-RPC标准协议,但是与谷歌ping服务不同的是百度的ping发送的xml格式不同,我们需要使用string节点包裹内容。
例如:
代码如下:


weblogUpdates.extendedPing


Ping服务的php实现方法,让网站快速被收录


http://s.jb51.net/


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


http://s.jb51.net/feed




根据上面提到的谷歌接口,我们只要改变一下提交的xml内容即可,当然百度ping服务返回的判断也是跟谷歌的不同,也可以做相应的修改,
下面是php的代码:
代码如下:
$baiduXML =

weblogUpdates.extendedPing

Ping服务的php实现方法,让网站快速被收录
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);
//下面是返回成功与否的判断(根据百度ping的接口说明)
if (strpos($res, "0"))
echo "PING成功";
else
echo "PING失败";

上面的代码就可以实现php的ping服务了。好吧,下面再给各位看管提供一个百度的ping服务代码,没办法谁让他那么独特那?
代码如下:
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

脚本之家
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成功";
}
else
{
echo "PING失败";
}
?>

此文很DT的让我浪费了N个草稿才写完,然后纷纭就发现需要搞个CODE的插件给WP装备上了。代码的问题真的很纠结,还有就是国人的WP主题没有支持分页的,这个让我很DT,说了半天,DT是啥?不知道……
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!