Last active
August 26, 2019 08:06
-
-
Save eto4detak/7cad36a93ded12ea98bd616308ce5769 to your computer and use it in GitHub Desktop.
php proxi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/////////////////////////////////////////////////////////////////////////////////////////// | |
/////// proxi | |
/////////////////////////////////////////////////////////////////////////////////////////// | |
function proxi($url, $postdata = null, $cookiefile = 'tmp/cookie.txt'){ | |
$proxy = '127.0.0.1:8888'; | |
//$proxyauth = 'user:password'; | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'ozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'); | |
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); | |
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_PROXY, $proxy); | |
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4); | |
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 9); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 6); | |
if( $postdata ){ | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); | |
} | |
$html = curl_exec($ch); | |
curl_close($ch); | |
return $html; | |
} | |
function multiproxi($urls = []){ | |
$multi = curl_multi_init(); | |
$hendles = []; | |
$htmls = []; | |
foreach ($urls as $url) { | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_multi_add_handle($multi, $ch); | |
$headles[ $url ] = $ch; | |
} | |
do { | |
$mrc = curl_multi_exec( $multi, $active); | |
} while ( $mrc == CURLM_CALL_MULTI_PERFORM); | |
while ($active && $mrc == CURLM_OK) { | |
if(curl_multi_select($multi) == -1){ | |
usleep(100); | |
} | |
} | |
do{ | |
$mrc = curl_multi_exec($multi, $active); | |
}while ($mrc == CURLM_CALL_MULTI_PERFORM); | |
foreach ($handles as $channel) { | |
$html = curl_multi_getcontent($channel); | |
$htmls[] = $html; | |
curl_multi_remove_handle($multi, $channel); | |
} | |
curl_multi_close($multi); | |
return $htmls; | |
} | |
/////////////////////////////////////////////////////////////////////////////////////////// | |
/////// script | |
/////////////////////////////////////////////////////////////////////////////////////////// | |
for ($i=0; $i < 100; $i++) { | |
$urls[] = 'http:/httpbin.org/get?i='.$i; | |
} | |
// $urls = array_chunk($urls, 5); | |
// foreach ($urls as $chunk) { | |
// $htmls = multiproxi($chunk); | |
// } | |
// https://github.com/php-curl-class/php-curl-class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment