Главная
Тексты
Это простенькая утилитка проверки списков проксей. Списки могут подаватся в скрипт как указанием файла (правда придется править в скрипте) или через поток ввода (STDIN). Соответсвенно самое простое использование
[root@localhost ~]# cat proxy.txt | ./proxycheck.php
где proxy.txt просто список вида
адрес:порт
адрес:порт
адрес:порт
результат проверки выводится в указанный файл или в STDOUT, например если имеем файл proxy.txt
200.65.127.161:3128
200.65.127.161:80
12.110.129.186:7212
211.242.42.52:80
80.58.205.61:80
81.140.160.17:3128
125.245.81.226:8080
то результат команды
[root@localhost ~]# cat proxy.txt | ./proxycheck.php
будет
200.65.127.161:3128 0.8921
200.65.127.161:80 0.6742
81.140.160.17:3128 0.5316
где цифирьки после адреса - время отклика.
ну и сам текст
<?php
/** 
* @package
* @author Vaulter <vaulter@nm.ru> develop 
* @version 06.12.2007 11:04:12  v1.0
*/
//OPTIONS s
$thisEnconding "UTF-8";
$srcfile STDIN;//'proxy.txt';//OR STDIN
$outfile STDOUT;//'proxy-check.txt';
$errfile 'proxy-check-errors.txt';//STDERR
$testurl 'http://ya.ru';
$timeout 5;//seconds
$curl_options = array(
    
CURLOPT_TIMEOUT => $timeout,
    
CURLOPT_HEADER => 1,
    
CURLOPT_NOBODY => 1,
    
CURLOPT_FAILONERROR => 1,
    
CURLOPT_RETURNTRANSFER => 1,
    
CURLOPT_USERAGENT => 1,
);

//start loading
if(! function_exists('curl_init'))
{
//need curl
    
echo 'script need curl'.PHP_EOL;
    exit;
}
$curl curl_init($testurl);
curl_setopt_array($curl$curl_options);
//get etalon 
$etalon =array();

$result curl_exec$curl );
if(
preg_match('/^Content-Length:\s*(.*?)$/ismx'$result$match))
    
$etalon['Content-Length'] = $match[1];
// ------------- SRC AND DEST
if(is_string($srcfile))  $src fopen($srcfile'rt');
else 
$src = & $srcfile;
if(
is_string($outfile))  $out fopen($outfile'wt');
else 
$out = & $outfile;
if(
is_string($errfile))  $err fopen($errfile'at');
else 
$err = & $errfile;
//------------ start iterate    
$i 0;
while(!
feof($src))//$proxies as $prox)
{
    
$i++;
    
$prox fgets($src);
    
$prox trim($prox,"\r\n");
    if(empty(
$prox)) continue;
    
curl_setopt($curlCURLOPT_PROXY$prox);
    
//echo $i.'. '.$prox.'...';
    //засекаем время
    
$now microtimeTRUE );
    
$r curl_exec($curl);
    
$delay microtimeTRUE ) - $now;
    if(
curl_errno($curl))
    {
        
fwrite($err$prox.' - '.curl_error($curl).PHP_EOL);
    }
    else
    {
        
//echo 'OK'.PHP_EOL;
        
if(preg_match('/^Content-Length:\s*(.*?)$/ismx'$r$m) && $etalon['Content-Length'] == $m[1])//valid
        
{
            
fprintf($out'%s %.4f'.PHP_EOL$prox$delay);
        }
    }
}
if(
is_string($srcfile)) fclose($src);
if(
is_string($outfile)) fclose($out);
if(
is_string($errfile)) fclose($err);
// завершение сеанса и освобождение ресурсов
curl_close($curl);
?>

брать здесь
Сайт создан в системе uCoz