好的,所以我基本上想要的是,一旦使用了来自“proxies.txt”的代理,然后将其移动到诸如“used.txt”之类的文件中,因此只有新的未使用的代理保留在“proxies.txt”中因为我的 id 抓取程序每次启动时都会从列表的最顶部开始,并且每 24 小时只能从每个代理抓取一次 ID。
{
switch(@$argv[1]) {
case '0':
default:
$list = fopen('proxies.txt', 'r');
while(!feof($list))
{
$proxy = fgets($list);
$idGen->generate($proxy);
}
fclose($list);
break;
}
$loop++;
usleep(50000);
$idGen->report('Starting loop #'.$loop);
}
还有一种方法可以让我删除死代理当前的 curl 设置是
$tries = 0;
$xData = '';
$timeout = 3;
//echo "Tries -> ";
while($xData=='' && $tries < 3) {
$ch = curl_init(); //curl init :D
curl_setopt($ch, CURLOPT_URL, 'website.com/idauth.php?t='.rand(100000000000,1000000000000000000000000000000000)); //url
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
$rdata = $data;
if(@$data{0} == '<') {
return;//Bad Proxy Detected.
}
if(strpos($data, 'Not Found') != FALSE) {
$data = '&UserId=0&k1=0&k2=0';
}
if($data != '&UserId=0&k1=0&k2=0') {
if(strpos($data, '&k2=0') != FALSE) {
$data = '&UserId=0&k1=0&k2=0';
} else {
$xData = $data;
}
} else {
echo $data."\n";
}
$tries++;
}
if($xData=='') {
return;//Dead Proxy
}