Been using mattseh's proxy finder lately, after lengthy testing you get lots of dead or not anonymous proxies. Testing these one by one with back to back curl calls is very time inefficient. So I've wrote a nice little function that uses the curl_multi functions to run the calls simultaneously.
I setup a simple script on another server that simply echos 'Hi'. This script will query a url and test the output vs 'Hi' (of course you can change it to whatever you like).
I'm hung over as fuck, have fun.
I setup a simple script on another server that simply echos 'Hi'. This script will query a url and test the output vs 'Hi' (of course you can change it to whatever you like).
I'm hung over as fuck, have fun.
Code:
<?php
function checkProxies($proxies){
//$proxies is an array of proxies in format ip:port,username:password
$url = 'http://someplace.tld/testphp.php'; //url to query
$return = 'Hi'; //expected reply
$count = count($proxies); //number of items in array
echo 'Number of proxies in list: ' . $count . '<br />';
$curl_arr = array();
$master = curl_multi_init(); //create multi curl resource
for($i = 0; $i < $count; $i++) {
$proxy = $proxies[$i]; //grab proxy from array
$curl_arr[$i] = curl_init(); // create new curl resource
curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, TRUE); //return the data don't output it outright
curl_setopt($curl_arr[$i], CURLOPT_HEADER, FALSE); //do not output the header info
curl_setopt($curl_arr[$i], CURLOPT_URL, $url); //set our url to query
curl_setopt($curl_arr[$i], CURLOPT_CONNECTTIMEOUT, 10); //set how long we'll give the proxy to respond in seconds in this instance 10 seconds
curl_setopt($curl_arr[$i], CURLOPT_HTTPPROXYTUNNEL, TRUE); //tunnel through the proxy
$cproxy = explode(',', $proxy); //split the proxy into an array $cproxy[0] will be ip:port $cproxy[1] will be username:password
curl_setopt($curl_arr[$i], CURLOPT_PROXY, $cproxy[0]); //set our proxy ip:port
if($cproxy[1]) { //test for username pass
curl_setopt($curl_arr[$i], CURLOPT_PROXYUSERPWD, $cprosy[1]); //set username:password
}
curl_multi_add_handle($master, $curl_arr[$i]); //add the current curl resource handle to the master
}
$running = null;
do {
curl_multi_exec($master,$running); //while there are running connections just keep looping
} while($running > 0);
echo 'Results: <br />';
$a = 0; //output array counter
for($i = 0; $i < $count; $i++) {
$rawdata = curl_multi_getcontent($curl_arr[$i]); //get returned data from curl handle
if($rawdata == $return){ //check the data returned vs what we expect
echo $i . '. Good Proxy: ' . $proxies[$i] . '<br /><br />';
$proxylist[$a] = $proxies[$i]; //it's a good proxy add it to our list
$a++;
} else echo $i . '. Bad Proxy: ' . $proxies[$i] . '<br /><br />';
}
echo 'Number of good proxies: ' . count($proxylist);
curl_multi_close($master); //destroy the multi curl resource
return $proxylist; //return an array of usable proxies
}
//start of main code
$proxies = file('proxies.txt'); //loads a file into an array each line being a new element
$proxies = checkProxies($proxies); //$proxies will be a returned array of usable proxies
?>