Ene*_*oma 5 php rss curl file-get-contents
我正在运行一个提要阅读器网站,那里会有很多RSS.我将尽可能经常同步这些提要,所以我找到了这两种方法.
1方法:使用CURL
$weblog_name = 'MyBlog';
$weblog_url = 'http://feeds.feedburner.com/myblog';
$ping_url = 'http://ping.feedburner.com';
$request = <<<EOT
<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>weblogUpdates.ping</methodName>
<params>
<param>
<value>
<string>$weblog_name</string>
</value>
</param>
<param>
<value>
<string>$weblog_url</string>
</value>
</param>
</params>
</methodCall>
EOT;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ping_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, trim($request));
$result = curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
第二种方法:file_get_contents
file_get_contents("http://feedburner.google.com/fb/a/pingSubmit?bloglink=http://feeds.feedburner.com/myblog");
Run Code Online (Sandbox Code Playgroud)
我的问题是哪个是更好,更快的解决方案,一次ping至少50个Feed?
Ene*_*oma 12
使用file_get_contents获取google.com(以秒为单位):
2.31319094
2.30374217
2.21512604
3.30553889
2.30124092
Run Code Online (Sandbox Code Playgroud)
CURL采取:
0.68719101
0.64675593
0.64326
0.81983113
0.63956594
Run Code Online (Sandbox Code Playgroud)
这是使用http://davidwalsh.name/php-timer-benchmark中的基准类