<?php
function get_random_proxy()
{
srand ((double)microtime()*1000000);
$f_contents = file ("proxy.txt");
$line = $f_contents[array_rand ($f_contents)];
return $line;
}
$proxy = get_random_proxy();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "example.com");
curl_setopt($ch, CURLOPT_PROXY,$proxy);
curl_setopt($ch, CURLOPT_TIMEOUT ,30);
curl_exec($ch);
curl_close($ch);
?>
如果在30秒內無法連接,curl將關閉連接。CURLOPT_TIMEOUT,是否有「其他」功能?
正如你所看到的,我使用代理列表。然而,一些代理服務器有時在30秒內連接有問題,而curl在30秒內無法加載時關閉連接。
我想嘗試另一個IP捲曲連接,如果捲曲超時達成。現在,如果ip不起作用,curl會關閉所有內容。我想嘗試另一個IP。那麼,請你給我建議一個功能?
編輯@rubayeet。添加新的代理功能
多數民衆贊成我的代理功能。我如何使用它的功能?函數get_random_proxy() srand((double)microtime()* 1000000); $ f_contents = file(「proxy.txt」); $ line = $ f_contents [array_rand($ f_contents)]; return $ line; } $ proxy = get_random_proxy(); – 2011-02-15 08:49:23