Показать сообщение отдельно

  #5  
Старый 30.01.2010, 09:51
Nosfer
Новичок
Регистрация: 10.01.2007
Сообщений: 16
С нами: 10174902

Репутация: 2
По умолчанию

Нужна помощь с рандомным перебором проксей, вот исхордный код

PHP код:


$match
='#https?://([^/\s]+)\S+#i';
preg_match_all($match$_POST['urls'], $matches);
$matches array_values(array_combine($matches[1],$matches[0]));

$mh curl_multi_init(); //Create multithread
$handles = array();
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"// set user agent 


//File with proxies to array
$proxyarr file('http://localhost/checkproxy/proxies.txt'FILE_IGNORE_NEW_LINES);

//echo $proxyarr[array_rand($proxyarr, 1)]."<br>";
 

for ($i=0$i<sizeof($matches);$i++) {
//Create URL
$request 'someurl';
// create a new single curl handle
$ch curl_init();
curl_setopt($chCURLOPT_URL$request);
curl_setopt($chCURLOPT_HEADER0);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_TIMEOUT600);
curl_setopt($chCURLOPT_USERAGENT$useragent); 
// add this handle to the multi handle
curl_multi_add_handle($mh,$ch);
// put the handles in an array to loop this later on
$handles[] = $ch;
}
// execute the multi handle
$running=null;
do {
curl_multi_exec($mh,$running);
// added a usleep for 0.25 seconds to reduce load
usleep (25000);
} while (
$running 0);
// get the content of the urls (if there is any)
for($i=0;$i<count($handles);$i++)  {
$output unserialize(curl_multi_getcontent($handles[$i]));

//ban check
if (!isset($output[ResultSet][totalResultsAvailable])) {
echo 
"<b>BAN</b><br>";
echo 
"$request";
exit(
0);
}

$result[$matches[$i]]=$output[ResultSet][totalResultsAvailable];
curl_multi_remove_handle($mh,$handles[$i]);

Скрипт ходит по http и дергает URL, который отдает ему массив.
Но сам ресурс имеет свойство периодически банить по IP, для этого и нужны прокси.
Я бы с удовольствием воткнул в цикл
Код:
for($i=0;$i<count($handles);$i++)
нечто вроде
Код:
curl_setopt($ch, CURLOPT_PROXY, $proxyarr[array_rand($proxyarr, 1)]);
и у меня даеже есть проверка на бан
Код:
if (!isset($output[ResultSet][totalResultsAvailable]))
но как сделать так, чтобы в случае бана он сделал для этого же урл новую итерацию забора контента, но уже с новой рандомной проксей из того же массива $proxyarr? Стоит также учесть тот момент, что на следующей прокси результата тоже может не быть и прокси надо перебирать до победного.

Я сам вижу лишь вариант в добавлением неуспешных элементов(урлов) в спец массив и повторным прогоном их с рандомными проксям, но решение кривовато.

Последний раз редактировалось Nosfer; 30.01.2010 в 09:55..
 
Ответить с цитированием