The script I'm using to check proxies isn't working correctly, is checking the proxies but always the same few proxies. Another issue, only port 80 proxies are displayed.
What I want, check all proxies (active or not) starting with oldest (time_checked asc), currently isn't working, the order is chaotic and if possible display all proxies not only port 80, all port 80 proxies are considered inactive, any help appreciated.
Values:
'active_proxies_number'=>10, //how many "active" proxies site/script
//should have at any given moment to choose from;
//the whole list will be much longer,
//but these proxies will be checked constantly
'number_to_check_at_time'=>10, //how many proxies should be checked in one function call
'add_new_at_time'=>10 //how many "inactive" proxies should be checked in one function call
function _check_proxies() {
$res = mysql_query("select `ip`, `port` from {$this->db_table} where `active`='1' order by `time_checked` asc limit {$this->number_to_check_at_time}");
if($res&&is_resource($res)&&mysql_num_rows($res) > 0) {
while($_proxAr = mysql_fetch_row($res)) {
$_speed = $this->_check_proxy(implode(':', $_proxAr));
if($_speed === false) {
mysql_query("update {$this->db_table} set `active`='0', `status`='0', `time_checked`=unix_timestamp() where `ip`='{$_proxAr[0]}'");
} else {
mysql_query("update {$this->db_table} set `time_checked`=unix_timestamp() where `ip`='{$_proxAr[0]}'");
}
}
}
list($current_num_proxies) = mysql_fetch_row(mysql_query("select count(*) from {$this->db_table} where `active`='1'"));
if($current_num_proxies > $this->active_proxies_number) {
$res = mysql_query("select `ip` from {$this->db_table} where `active`='1' order by `speed` desc limit " . ($current_num_proxies - $this->active_proxies_number));
while($row = mysql_fetch_row($res)) {
mysql_query("update {$this->db_table} set `active`='0' where `ip`='{$row[0]}'");
}
$current_num_proxies = $this->active_proxies_number;
}
$_diff = $this->active_proxies_number - $current_num_proxies;
$query = "select `ip`, `port` from {$this->db_table} where `active`='0' and (`status` is null or `status`='1')";
if(!$this->use_transparent) $query .= " AND `type`!='0'";
if(!$this->use_anonymous) $query .= " AND `type`!='1'";
$query .= " order by `time_added` desc, `time_checked` asc";
$res = mysql_query($query);
if(!$res||!is_resource($res)||mysql_num_rows($res) < 1) {
$_diff = 0;
$query = "select `ip`, `port` from {$this->db_table} where `active`='0' and `status`='0'";
if(!$this->use_transparent) $query .= " AND `type`!='0'";
if(!$this->use_anonymous) $query .= " AND `type`!='1'";
$query .= " order by `time_added` desc, `time_checked` asc";
$res = mysql_query($query);
if(!$res||!is_resource($res)||mysql_num_rows($res) < 1) return false;
}
$new_added = 0;
while($row = mysql_fetch_row($res)) {
$new_added++;
$_speed = $this->_check_proxy(implode(':', $row));
if($_speed === false) {
mysql_query("update {$this->db_table} set `active`='0', `status`='0', `time_checked`=unix_timestamp() where `ip`='{$row[0]}'");
if(!$_diff&&$new_added >= $this->add_new_at_time) break;
continue;
}
if($_diff) {
mysql_query("update {$this->db_table} set `active`='1', `status`='1', `time_checked`=unix_timestamp(), `speed`='$_speed' where `ip`='{$row[0]}'");
$_diff--;
if(!$_diff&&$new_added >= $this->add_new_at_time) break;
continue;
}
$_halfspeed = sprintf("%.3f", $_speed*2);
if($_halfspeed < $this->speed_limit) $res2 = mysql_query("select `ip` from {$this->db_table} where `active`='1' and `speed`>=$_halfspeed order by `speed` desc limit 1");
if($_halfspeed < $this->speed_limit&&$res2&&is_resource($res2)&&mysql_num_rows($res2) > 0) {
list($_oldip) = mysql_fetch_row($res2);
mysql_query("update {$this->db_table} set `active`='0' where `ip`='$_oldip'");
mysql_query("update {$this->db_table} set `active`='1', `status`='1', `time_checked`=unix_timestamp(), `speed`='$_speed' where `ip`='{$row[0]}'");
} else {
mysql_query("update {$this->db_table} set `active`='0', `status`='1', `time_checked`=unix_timestamp(), `speed`='$_speed' where `ip`='{$row[0]}'");
}
if(!$_diff&&$new_added >= $this->add_new_at_time) break;
}
return true;
}