Пример #1
0
 public static function proxy_test()
 {
     $options = array(CURLOPT_URL => 'http://www.baidu.com', CURLOPT_REFERER => 'http://www.baidu.com', CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)', CURLOPT_TIMEOUT => 10, CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HEADER => 0, CURLOPT_NOSIGNAL => true, CURLOPT_DNS_USE_GLOBAL_CACHE => true, CURLOPT_DNS_CACHE_TIMEOUT => 86400, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false);
     if (empty(self::$CURL_PROXY_ARRAY)) {
         if (empty(self::$CURL_PROXY)) {
             return false;
         }
         self::$CURL_PROXY_ARRAY = explode("\n", self::$CURL_PROXY);
         // socks5://127.0.0.1:1080@username:password
     }
     if (empty(self::$CURL_PROXY_ARRAY)) {
         return false;
     }
     $rand_keys = array_rand(self::$CURL_PROXY_ARRAY, 1);
     $proxy = self::$CURL_PROXY_ARRAY[$rand_keys];
     $proxy = trim($proxy);
     $options = self::proxy($options, $proxy);
     $ch = curl_init();
     curl_setopt_array($ch, $options);
     curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     if ($info['http_code'] == 200) {
         return $proxy;
     } else {
         unset(self::$CURL_PROXY_ARRAY[$rand_keys]);
         return self::proxy_test();
     }
 }