$proxy = new Proxy();
$curlData = $proxy->curl($page);
$html = HtmlDomParser::str_get_html($curlData);
$find = $this->is_find($html, ".leftcol > .area > .listItem");
if ($find == 0) {
do {
$proxy->changeProxyIdentity();
$this->new_ip = $this->getIp();
$curlData = $proxy->curl($page);
$html = HtmlDomParser::str_get_html($curlData);
$find = $this->is_find($html, ".leftcol > .area > .listItem");
} while ($find == 0);
}
проверка
protected function is_find($dom, $classes){
if(!method_exists($dom, 'find')){
return 0;
}
$find = $dom->find($classes);
if (empty($find)){
return 0; // if пусто
}else{
return $find;
}
}
Класс
class Proxy {
private $ch, $proxy;
function __construct() {
// $torSocks5Proxy = "socks5://127.0.0.1:9050";
$torSocks5Proxy = "127.0.0.1:9050";
$this -> ch = curl_init();
curl_setopt( $this -> ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5 );
curl_setopt( $this -> ch, CURLOPT_PROXY, $torSocks5Proxy );
curl_setopt( $this -> ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $this -> ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $this -> ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $this -> ch, CURLOPT_HEADER, false );
}
public function curl( $url, $postParameter = null ) {
if ( is_array($postParameter) && count( $postParameter ) > 0 )
curl_setopt( $this -> ch, CURLOPT_POSTFIELDS, $postParameter );
curl_setopt( $this -> ch, CURLOPT_URL, $url );
return curl_exec( $this -> ch );
}
public function changeProxyIdentity() {
$ip = '127.0.0.1';
$port = '9051';
$fp = fsockopen( $ip, $port, $error_number, $err_string, 10 );
if ( !$fp ) {
echo "Error while changing Tor proxy identity: {$error_number} : {$err_string}";
return false;
} else {
fwrite( $fp, "AUTHENTICATE\n" );
$received = fread( $fp, 512 );
fwrite( $fp, "signal NEWNYM\n" );
$received = fread( $fp, 512 );
}
sleep(3);
fclose( $fp );
return $received;
}
function __destruct() {
curl_close( $this -> ch );
}
}
Смена IP проходит но почему то контент не приходит в чем ошибся?
Суть такая если не пришел контент сменить IP и пробовать опять