if ($newtry) { if ($errors++ > 3) { echo "Abort: too many google errors! {$NL}{$NL}"; sleep(5); break; } $res = proxy_api("rotate"); $ip = ""; if ($res <= 0) { echo "Error: API connection failed (Error {$res}), retry.{$NL}{$NL}{$NL}"; sleep(10); } else { echo "API: Received proxy IP {$PROXY['external_ip']} on port {$PROXY['port']}{$NL}"; } echo "Rotated IP and retrying{$NL}"; $ch = new_curl_session($ch); continue; } $skip = 0; // now we test if (more) results are available if (strstr($htmdata, "/images/yellow_warning.gif")) { echo "No (more) results left{$NL}"; $skip = 1; } if (!$skip) { $len = strlen($htmdata); echo "\t Received {$len} bytes{$NL}"; // Now we parse the html content, putting it into a DOM tree $dom = new domDocument(); $dom->strictErrorChecking = false; $dom->preserveWhiteSpace = true;
function rotate_proxy() { global $PROXY; global $ch; global $NL; $max_errors = 3; $success = 0; while ($max_errors--) { $res = proxy_api("rotate"); // will fill $PROXY $ip = ""; if ($res <= 0) { verbose("API error: Proxy API connection failed (Error {$res}). trying again soon..{$NL}{$NL}"); sleep(21); // retry after a while } else { verbose("API success: Received proxy IP {$PROXY['external_ip']} on port {$PROXY['port']}{$NL}"); $success = 1; break; } } if ($success) { $ch = new_curl_session($ch); return 1; } else { return "API rotation failed. Check license, firewall and API credentials.{$NL}"; } }