This example of this article has shared the check Agent IP validity PHP code, stability, such as error rate and query usage
/** +-----------------------------------------------------------------------------* Check Agent IP information validity +----------------- ------------------------------------------------------------* @param string $proxy _ip [117.95.100.126:8998] * @param int $times Number of checks * @return array * @author elinx <654753115@qq.com> 2016-07-29 +-------------------------------- ---------------------------------------------*/function Check_proxy_ip_info ($proxy _ip=false, $times =10) {$header = Array (///"get/http/1.1",///"HOST:www.baidu.com", "Accept:application/json", "Accept-encoding:gzip, Deflate "," accept-language:en-us,en;q=0.8 "," Content-type:application/json "," user-agent:mozilla/5.0 (Windo WS NT 10.0;
WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/51.0.2704.106 safari/537.36 ",);
$url = ' http://www.baidu.com/'; $result [' succeed_times '] = 0; Number of successes $result [' defeat_times '] = 0; Number of failures $result [' total_spen '] = 0; Total used for ($i =0; $i < $times;
$i + +) {$s = Microtime ();
$curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $url); Set the URL of the transmission curl_setopt ($curl, Curlopt_httpheader, $header);
Send HTTP header curl_setopt ($curl, Curlopt_returntransfer, 1); curl_setopt ($curl, curlopt_encoding, ' gzip,deflate '); Decode compressed file curl_setopt ($curl, Curlopt_ssl_verifypeer, false); Do not verify the SSL book curl_setopt ($curl, Curlopt_ssl_verifyhost, false); Do not verify SSL certificate if (@ $proxy _ip!= false) {//Use proxy IP curl_setopt ($curl, Curlopt_httpheader, Array (' Client_ Ip: '. Mt_rand (0, 255). '. '. Mt_rand (0, 255). Mt_rand (0, 255).
Mt_rand (0, 255),)); curl_setopt ($curl, Curlopt_httpheader, Array (' X-forwarded-for: '. Mt_rand (0, 255). " Mt_rand (0, 255). Mt_rand (0, 255).
Mt_rand (0, 255),));
curl_setopt ($curl, Curlopt_proxytype, curlproxy_http);
curl_setopt ($curl, Curlopt_proxy, $proxy _ip); curl_setopt ($curl, Curlopt_cookiefile, DirName (__file__). '
/cookie.txt '); curl_setopt ($curl, Curlopt_cookiejar, DirName (__file__).
/cookie.txt '); curl_setopt ($curl, Curlopt_timeout, 30); Set timeout limit Prevent dead loops//$response _header = Curl_getinfo ($curl);
Gets the return response header $content = curl_exec ($curl);
if (Strstr ($content, ' Baidu, you Know ')} {$result [' list '] [$i] [' status '] = 1;
$result [' succeed_times '] + + 1;
else {$result [' list '] [$i] [' status '] = 0;
$result [' defeat_times '] + + 1;
} $e = Microtime ();
$result [' total_spen '] = ABS ($e-$s);
$result [' list '] [$i] [' spen '] = ABS ($e-$s);
$result [' list '] [$i] [' content '] = Json_encode ($content, true);
$result [' list '] [$i] [' response_header '] = $response _header; $result [' precent '] = (Number_format ($result [' Succeed_times ']/$times, 4) *100). '
%';
$result [' average_spen '] = Number_format ($result [' Total_spen ']/$times, 4);
return $result; }
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.