我正在運行一個Feed閱讀器網站,那裏會有很多RSS。我將不得不盡可能經常同步這些提要,所以我找到了這兩種方法。CURL或file_get_contents更新供稿列表?
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);
第二種方法:的file_get_contents
file_get_contents("http://feedburner.google.com/fb/a/pingSubmit?bloglink=http://feeds.feedburner.com/myblog");
我的問題是,這是更好,更快的解決方案來ping至少50提要一次?
我不熟悉的捲曲,它獲得的內容?我的意思是它是如何工作的? 另外,50個get_file_contents會一次很慢嗎? – EnexoOnoma
cURL也會得到http請求的頭文件。 您可以在cURL中添加自己的請求標題,發佈變量和代理服務器。但是,對於簡單的獲取請求,cURL是不必要的。 我發現cURL需要在我的wamp服務器上花費10毫秒apache2.2.17 php5.3.5 for http://www.google.com –
@mtopia它並沒有真正改變,因爲get_file_contents是同步的,即下一行被執行只有在這條線完全執行之後 –