PHP Code to check proxy IP validity

Source: Internet
Author: User
Tags ssl book ssl certificate
This article mainly for you in detail the PHP check proxy IP validity code, has a certain practical value, interested in small partners can refer to

Examples of this article for everyone to share the check agent IP validity PHP code, stability, such as error rate and query time

/** +-----------------------------------------------------------------------------* Check proxy IP information validity +----------------- ------------------------------------------------------------* @param string $proxy _ip [117.95.100.126:8998] * @param int $times Check count * @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, DEFL Ate "," accept-language:en-us,en;q=0.8 "," Content-type:application/json "," user-agent:mozilla/5.0 (Windows NT 1 0.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 time for ($i =0; $i < $times; $i + +) {$s = MicrotIME ();    $curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $url); Set the URL of the transfer 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); No authentication certificate SSL book curl_setopt ($curl, Curlopt_ssl_verifyhost, false); Do not verify the 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 to 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;}

Summary: The above is the entire content of this article, I hope to be able to help you learn.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.