Multi-threaded cURL

Source: Internet
Author: User
Multi-threaded cURL
This is a flexible multi-thread call cURL.
This is different from the sample provided in the php manual http://us2.php.net/manual/zh/function.curl-multi-select.php, the code execution efficiency is much higher
There are two files in this section. one is a muti_curl file, which contains two classes.
One method is to use, here is to check whether the proxy ip is available in batches

  1. Class request_setting {
  2. Public $ url = false;
  3. Public $ method = 'get ';
  4. Public $ post_data = null;
  5. Public $ headers = null;
  6. Public $ options = null;
  7. Function _ construct ($ url, $ method = "GET", $ post_data = null, $ headers = null, $ options = null ){
  8. $ This-> url = $ url;
  9. $ This-> method = $ method;
  10. $ This-> post_data = $ post_data;
  11. $ This-> headers = $ headers;
  12. $ This-> options = $ options;
  13. }
  14. Public function _ destruct (){
  15. Unset ($ this-> url, $ this-> method, $ this-> post_data, $ this-> headers, $ this-> options );
  16. }
  17. }
  18. /*************************************** **************************************** ****************
  19. Batch operation class
  20. **************************************** **************************************** ***********/
  21. Class muti_curl {
  22. Protected $ thread_size = 100;
  23. Protected $ timeout = 30;
  24. Private $ callback;
  25. Protected $ options = array (
  26. CURLOPT_SSL_VERIFYPEER => false, // after the cURL is disabled, it is terminated from the server for verification. Use the CURLOPT_CAINFO option to set the certificate. use the CURLOPT_CAPATH option to set the certificate Directory. if CURLOPT_SSL_VERIFYPEER (default value: 2) is enabled, set CURLOPT_SSL_VERIFYHOST to TRUE or FALSE. The default value is TRUE since cURL 7.10. The installation is bound by default starting from cURL 7.10.
  27. CURLOPT_RETURNTRANSFER => true, // return the information obtained by curl_exec () in the form of a file stream, instead of directly entering
  28. CURLOPT_CONNECTTIMEOUT => 15,
  29. CURLOPT_TIMEOUT => 30,
  30. // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0, // it is better to use this to capture data when using a proxy.
  31. // CURLOPT_AUTOREFERER => false, // when based on Location: redirection, the Referer: Information in the header is automatically set.
  32. // CURLOPT_BINARYTRANSFER => false, // when CURLOPT_RETURNTRANSFER is enabled, the native (Raw) output is returned.
  33. // CURLOPT_COOKIESESSION => true, // When enabled, curl will only pass one session cookie and ignore other cookies. by default, cURL will return all cookies
  34. // CURLOPT_CRLF => false, // When enabled, convert Unix line breaks to carriage return line breaks.
  35. // CURLOPT_DNS_USE_GLOBAL_CACHE => false, // A global DNS cache is enabled when it is enabled. this option is thread-safe and enabled by default.
  36. // CURLOPT_FAILONERROR => false, // The HTTP status code is displayed. the default behavior is to ignore the HTTP information whose number is less than or equal to 400.
  37. // CURLOPT_FILETIME => true, // When enabled, the system tries to modify the information in the remote document. The result is returned through the CURLINFO_FILETIME option of the curl_getinfo () function. Curl_getinfo ().
  38. // CURLOPT_FOLLOWLOCATION => false, // When enabled, the "Location:" returned by the server will be recursively returned to the server in the header. you can use CURLOPT_MAXREDIRS to limit the number of recursive responses.
  39. // CURLOPT_FORBID_REUSE => true, // force disconnect after the interaction is completed and cannot be reused.
  40. // CURLOPT_FRESH_CONNECT => true, // force a new connection to replace the connection in the cache.
  41. // CURLOPT_FTP_USE_EPRT => false, // When FTP download is enabled, use the EPRT (or LPRT) command. If it is set to FALSE, disable EPRT and LPRT and use the PORT command only.
  42. // CURLOPT_FTP_USE_EPSV => false, // When enabled, try the EPSV command before returning to PASV mode during FTP transmission. Disable the EPSV command when set to FALSE.
  43. // CURLOPT_FTPAPPEND => false, // When enabled, append the data to the file instead of overwriting it.
  44. // CURLOPT_FTPASCII => false, // The alias of CURLOPT_TRANSFERTEXT.
  45. // CURLOPT_FTPLISTONLY => false, // only the FTP directory name is listed when enabled.
  46. // CURLOPT_HEADER => true, // When enabled, the header file information is output as a data stream.
  47. // CURLINFO_HEADER_OUT => false, // The request string of the tracking handle when enabled.
  48. // CURLOPT_HTTPGET => true, // When enabled, the HTTP method is set to GET. because GET is the default value, it is used only when it is modified.
  49. // CURLOPT_HTTPPROXYTUNNEL => true, // it will be transmitted through the HTTP proxy when enabled.
  50. // CURLOPT_MUTE => true, // When enabled, all the modified parameters in the cURL function are restored to the default value.
  51. // CURLOPT_NETRC => false, // after the connection is established, access ~ /. The netrc file obtains the user name and password to connect to the remote site.
  52. // CURLOPT_NOBODY => true.
  53. // CURLOPT_NOPROGRESS => false, // disable the curl transmission progress bar when enabled. this option is enabled by default.
  54. // CURLOPT_NOSIGNAL => false, // When enabled, ignore all the signals sent to php by curl. This option is enabled by default during SAPI multi-thread transmission. CURL 7.10 is added.
  55. // CURLOPT_POST => false, // When enabled, a conventional POST request is sent. the type is application/x-www-form-urlencoded, just like form submission.
  56. // CURLOPT_PUT => false, // When enabled, files can be sent over HTTP. both CURLOPT_INFILE and CURLOPT_INFILESIZE must be set.
  57. // CURLOPT_TRANSFERTEXT => false, // use ASCII mode for FTP transmission after enabling. For LDAP, it retrieves plain text information rather than HTML. In Windows, STDOUT is not set to binary mode.
  58. // CURLOPT_UNRESTRICTED_AUTH => true, // The username and password information is continuously appended to multiple locations in the header generated by CURLOPT_FOLLOWLOCATION, even if the domain name has changed.
  59. // CURLOPT_UPLOAD => false, // enable and allow file upload.
  60. // CURLOPT_VERBOSE => true, // When enabled, all information is reported and stored in STDERR or the specified CURLOPT_STDERR.
  61. );
  62. Private $ headers = array ();
  63. Private $ requests = array ();
  64. Private $ requestMap = array ();
  65. /*********************
  66. Construct a callback function
  67. ********************/
  68. Function _ construct ($ callback = null ){
  69. $ This-> callback = $ callback;
  70. }
  71. /*************************************** *****************************
  72. Reload the _ get method
  73. **************************************** ***************************/
  74. Public function _ get ($ name ){
  75. Return (isset ($ this-> {$ name }))? $ This-> {$ name}: null;
  76. }
  77. /*************************************** ******************************
  78. Reload _ set
  79. **************************************** ***************/
  80. Public function _ set ($ name, $ value ){
  81. // Add a setting to headers.
  82. If ($ name = "options" | $ name = "headers "){
  83. $ This-> {$ name }=$ value + $ this-> {$ name };
  84. } Else {
  85. $ This-> {$ name} = $ value;
  86. }
  87. Return true;
  88. }
  89. // Add a request
  90. Public function add ($ request ){
  91. $ This-> requests [] = $ request;
  92. Return true;
  93. }
  94. Public function request ($ url, $ method = "GET", $ post_data = null, $ headers = null, $ options = null ){
  95. $ This-> requests [] = new request_setting ($ url, $ method, $ post_data, $ headers, $ options );
  96. Return true;
  97. }
  98. Public function get ($ url, $ headers = null, $ options = null ){
  99. Return $ this-> request ($ url, "GET", null, $ headers, $ options );
  100. }
  101. Public function post ($ url, $ post_data = null, $ headers = null, $ options = null ){
  102. Return $ this-> request ($ url, "POST", $ post_data, $ headers, $ options );
  103. }
  104. Private function single_curl (){
  105. $ Ch = curl_init (); // Initialization
  106. $ Request = array_shift ($ this-> requests); // removes the first unit and serves as the result.
  107. $ Options = $ this-> get_options ($ request); // Obtain the unit settings
  108. Curl_setopt_array ($ ch, $ options); // batch settings
  109. $ Output = curl_exec ($ ch );
  110. $ Curl_info = curl_getinfo ($ ch );
  111. If ($ this-> callback ){
  112. $ Callback = $ this-> callback;
  113. If (is_callable ($ this-> callback )){
  114. Call_user_func ($ callback, $ output, $ curl_info, $ request );
  115. }
  116. }
  117. Else
  118. Return $ output;
  119. Return true;
  120. }
  121. Private function rolling_curl ($ thread_size = null ){
  122. If ($ thread_size ){
  123. $ This-> thread_size = $ thread_size;
  124. }
  125. If (count ($ this-> requests) <$ this-> thread_size ){
  126. $ This-> thread_size = count ($ this-> requests );
  127. }
  128. If ($ this-> thread_size <2 ){
  129. $ Errorinfo = 'the thread size must be greater than 1 !!!! ';
  130. Throw new Exception ($ errorinfo );
  131. }
  132. $ Queue = curl_multi_init ();
  133. // Add the task queue in the thread
  134. For ($ I = 0; $ I <$ this-> thread_size; $ I ++ ){
  135. $ Ch = curl_init ();
  136. $ Options = $ this-> get_options ($ this-> requests [$ I]);
  137. Curl_setopt_array ($ ch, $ options); // get the settings
  138. Curl_multi_add_handle ($ queue, $ ch); // add
  139. $ Key = (string) $ ch;
  140. $ This-> requestMap [$ key] = $ I;
  141. }
  142. Do {
  143. While ($ statu_run_muti_exec = curl_multi_exec ($ queue, $ active) = CURLM_CALL_MULTI_PERFORM );
  144. If ($ statu_run_muti_exec! = CURLM_ OK) {break ;}
  145. // Process a completed request
  146. While ($ done = curl_multi_info_read ($ queue )){
  147. $ Curl_info = curl_getinfo ($ done ['handle']);
  148. $ Output = curl_multi_getcontent ($ done ['handle']);
  149. $ Callback = $ this-> callback;
  150. If (is_callable ($ callback )){
  151. $ Key = (string) $ done ['handle'];
  152. $ Request = $ this-> requests [$ this-> requestMap [$ key];
  153. Unset ($ this-> requestMap [$ key]); // this destroy variable is very handsome
  154. Call_user_func ($ callback, $ output, $ curl_info, $ request );
  155. }
  156. // Add an unprocessed request to a completed queue
  157. If ($ I <count ($ this-> requests) & isset ($ this-> requests [$ I]) & $ I <count ($ this-> requests )){
  158. $ Ch = curl_init ();
  159. $ Options = $ this-> get_options ($ this-> requests [$ I]);
  160. Curl_setopt_array ($ ch, $ options );
  161. Curl_multi_add_handle ($ queue, $ ch );
  162. $ Key = (string) $ ch;
  163. $ This-> requestMap [$ key] = $ I;
  164. $ I ++;
  165. }
  166. Curl_multi_remove_handle ($ queue, $ done ['handle']);
  167. Echo "done ";
  168. Print_r ($ queue );
  169. Print_r ($ done );
  170. }
  171. // This step is very important. if you need to reset the timeout time after completing one step
  172. // The key point here is to ensure that at least one of the requests in all the threads for the first time is valid. otherwise, none of the requests will be effective for the first time, cause $ active = 0, so do not execute the following
  173. If ($ active> 0 ){
  174. Curl_multi_select ($ queue, $ this-> timeout );
  175. }
  176. } While ($ active );
  177. Curl_multi_close ($ queue );
  178. Return true;
  179. }
  180. Public function execute ($ thread_size = null ){
  181. // Determine the size of thread_size. if there is only one request, the single-thread mode is used.
  182. If (count ($ this-> requests) = 1 ){
  183. Return $ this-> single_curl ();
  184. } Else {
  185. Return $ this-> rolling_curl ($ thread_size );
  186. }
  187. }
  188. Private function get_options ($ request ){
  189. $ Options = $ this->__ get ('options ');
  190. If (ini_get ('safe _ mode') = 'off' |! Ini_get ('safe _ mode ')){
  191. // $ Options [CURLOPT_FOLLOWLOCATION] = 1;
  192. // $ Options [CURLOPT_MAXREDIRS] = 5;
  193. }
  194. $ Headers = $ this->__ get ('headers ');
  195. If ($ request-> options ){
  196. $ Options = $ request-> options + $ options;
  197. }
  198. $ Options [CURLOPT_URL] = $ request-> url;
  199. // Set the post option and header option respectively below
  200. If ($ request-> post_data ){
  201. $ Options [CURLOPT_POST] = 1;
  202. $ Options [CURLOPT_POSTFIELDS] = $ request-> post_data;
  203. }
  204. If ($ headers ){
  205. $ Options [CURLOPT_HEADER] = 0;
  206. $ Options [CURLOPT_HTTPHEADER] = $ headers;
  207. }
  208. Return $ options;
  209. }
  210. Public function _ destruct (){
  211. Unset ($ this-> thread_size, $ this-> callback, $ this-> options, $ this-> headers, $ this-> requests );
  212. }
  213. }
  214. ?>

  1. Header ("content-type: text/html; charset = utf-8 ");
  2. Require ("muti_curl_class.php ");
  3. Set_time_limit (0 );
  4. $ Sucesesnum = 0;
  5. $ Good_proxy = array ();
  6. Function request_callback ($ response, $ info, $ request ){
  7. Global $ sucesesnum, $ good_proxy;
  8. // The following regular expression can display the returned results selectively.
  9. /* If (preg_match ("~(.*?)~ I ", $ response, $ out )){
  10. $ Title = $ out [1];
  11. }*/
  12. // Echo'
    '. $ Response .'
    ';
  13. Echo'
    ';
  14. // Check the response, that is, $ response to determine whether there are set characters in the response. If yes, the agent is used successfully.
  15. If ($ response! = False & substr_count ($ response, 'user-agent: Baiduspider ')> = 1 ){
  16. // $ Result = true;
  17. Echo "true
    ";
  18. // Echo $ request [options] [1, 10004];
  19. // Print_r ($ request-> options );
  20. Echo $ request-> options [CURLOPT_PROXY];
  21. $ Good_proxy [] = $ request-> options [CURLOPT_PROXY];
  22. }
  23. Echo'
    The --> '. $ sucesesnum.' <--- use: '. $ info ['total _ time'];
  24. // Print_r ($ request );
  25. // Echo $ request-> url;
  26. $ Sucesesnum ++;
  27. Echo "";
  28. }
  29. $ Params = array_merge ($ _ GET, $ _ POST); // obtain the address of the passed proxy ip address.
  30. $ Result = $ proxy_ip = trim ($ params ['IP']);
  31. $ Timeout = intval (trim ($ params ['timeout']);
  32. If ($ timeout <3) {$ timeout = 3 ;}
  33. If ($ timeout> 300) {$ timeout = 300 ;}
  34. $ Thread_size = intval (trim ($ params ['thread _ size']);
  35. If ($ thread_size <5) {$ thread_size = 5 ;}
  36. If ($ thread_size> 300) {$ thread_size = 300 ;}
  37. If ($ proxy_ip = ''){
  38. Echo 'Enter the IP address !! ';
  39. Return;
  40. }
  41. $ Replace_arr1 = array ('', 'qq proxy: ', 'dn28. com ', 'qqip', 'qq proxy', 'qq proxy IP', 'proxy ip: ', 'Ip:', 'proxy IP ','"', "'",'\\','/','');
  42. $ Result = str_replace ($ replace_arr1, array (''), $ result );
  43. $ Result = str_replace (",", "\ n", $ result );
  44. $ ResArr = explode ("\ n", $ result );
  45. Foreach ($ resArr as $ k => $ v ){
  46. $ PosProxy = getPos ($ v ,'@');
  47. If ($ posProxy === false ){
  48. If (! Empty ($ v) {$ proxyip_and_port = $ v ;}
  49. } Else {
  50. $ Proxyip_and_port = substr ($ v, 0, $ posProxy );
  51. }
  52. $ NewRes [] = trim ($ proxyip_and_port );
  53. }
  54. Print_r ($ newRes );
  55. // Die ();
  56. $ Option_setting = array (
  57. CURLOPT_SSL_VERIFYPEER => 0,
  58. CURLOPT_RETURNTRANSFER => true,
  59. CURLOPT_CONNECTTIMEOUT => 5,
  60. CURLOPT_TIMEOUT => 30,
  61. CURLOPT_HEADER => false,
  62. CURLOPT_PROXY => '', // Set the proxy location here
  63. );
  64. $ Url = 'http: // www.baidu.com/robots.txt ';
  65. $ Btime = time ();
  66. $ Rc = new muti_curl ("request_callback ");
  67. $ Rc-> timeout = $ timeout;
  68. $ Rc-> thread_size = $ thread_size;
  69. Foreach ($ newRes as $ v ){
  70. $ Option_setting [CURLOPT_PROXY] = $ v;
  71. $ Request = new request_setting ($ url, $ method = "GET", $ post_data = null, $ header = null, $ option_setting );
  72. $ Rc-> add ($ request );
  73. }
  74. $ Rc-> execute ();
  75. $ Etime = time ();
  76. $ Usedtime = $ etime-$ btime;
  77. Echo 'all'. $ sucesesnum. 'use'. $ usedtime;
  78. Echo '';
  79. $ Good_proxy = array_unique ($ good_proxy );
  80. $ Str = '';
  81. Foreach ($ good_proxy as $ v ){
  82. $ Str. = "'". trim ($ v )."',";
  83. }
  84. $ Str = str_replace ('','', $ str );
  85. $ Str = preg_replace ('/\ s +/', '', $ str );
  86. Echo $ str .'
    ';
  87. Var_export ($ good_proxy );
  88. // Var_dump ($ good_proxy );
  89. //************************************** **************************************** ********************
  90. // ********************************* Only uses one function
  91. Function parseProxyInfo ($ proxyStr ){
  92. // $ ProxyStr = '192. 115.207.25: 80 @ HTTP; Chengdu Sichuan Normal University ';
  93. $ PosIp = getPos ($ proxyStr ,':');
  94. $ Ip = substr ($ proxyStr, 0, $ posIp );
  95. $ PosPort = getPos ($ proxyStr ,'@');
  96. $ Port = substr ($ proxyStr, $ posIp + 1, $ posPort-$ posIp-1 );
  97. $ PosType = getPos ($ proxyStr ,';');
  98. $ Type = substr ($ proxyStr, $ posPort + 1, $ posType-$ posPort-1 );
  99. $ Location = substr (strstr ($ proxyStr, ';'), 1 );
  100. Return array (
  101. 'IP' => $ ip,
  102. 'Port' => $ port,
  103. 'Type' => $ type,
  104. 'Location' => $ location
  105. );
  106. }
  107. Function getPos ($ haystack, $ needle ){
  108. Return strpos ($ haystack, $ needle );
  109. }
  110. Function check_proxy_is_useful ($ model, $ proxy_info_arr = array ()){
  111. Global $ params, $ config;
  112. If ($ model = 'Singles '){
  113. $ Proxy_port = intval (trim ($ params ['port']);
  114. $ Check_proxy_url = $ config ['verify _ url'];
  115. $ Proxy_time_out = intval (trim ($ params ['timeout']);
  116. $ Retry = intval (trim ($ params ['retry']);
  117. $ Proxy_ip = trim ($ params ['IP']);
  118. $ Proxy = new proxy ($ proxy_ip, $ proxy_port, $ check_proxy_url, $ proxy_time_out, $ retry );
  119. // String success is returned if the call succeeds. if the call fails, boolean false is returned.
  120. $ Result = $ proxy-> check_proxy ();
  121. // Var_dump ($ result );
  122. $ Proxy_str_success = ''. $ proxy_ip. ':'. $ proxy_port. '@'. 'http proxy verification successful! ';
  123. $ Proxy_str_failed = ''. $ proxy_ip. ':'. $ proxy_port. '@'. 'http proxy verification failed! ';
  124. Return $ result! = False? $ Proxy_str_success: $ proxy_str_failed;
  125. } Elseif ($ model = 'collect '){
  126. $ Proxy_port = intval (trim ($ proxy_info_arr ['port']);
  127. $ Check_proxy_url = $ config ['verify _ url'];
  128. $ Proxy_time_out = intval (trim ($ params ['timeout']);
  129. $ Retry = intval (trim ($ params ['retry']);
  130. $ Proxy_ip = trim ($ proxy_info_arr ['IP']);
  131. /* Echo $ proxy_ip .'
    ';
  132. Echo $ proxy_port .'
    ';
  133. Echo $ check_proxy_url .'
    ';
  134. Echo $ proxy_time_out .'
    ';
  135. Echo $ retry .'
    ';*/
  136. If (! Isset ($ proxy )){
  137. $ Proxy = new proxy ($ proxy_ip, $ proxy_port, $ check_proxy_url, $ proxy_time_out, $ retry );
  138. }
  139. // String success is returned if the call succeeds. if the call fails, boolean false is returned.
  140. $ Result = $ proxy-> check_proxy ();
  141. Return $ result;
  142. }
  143. }
  144. Function get_single (){
  145. Global $ params, $ config;
  146. $ Proxy_ip = trim ($ params ['IP']);
  147. If ($ proxy_ip = ''){
  148. Echo 'Enter the IP address !! ';
  149. Return;
  150. }
  151. Echo check_proxy_is_useful ('Single ');
  152. }
  153. Function get_proxy_by_collect (){
  154. Global $ params, $ config;
  155. $ Params ['URL'] = trim ($ params ['URL']);
  156. If ($ params ['URL'] = ''){
  157. Echo 'Enter the url! ';
  158. Return;
  159. }
  160. // $ Url = 'http: // www.dn28.com/html/75/n-5175.html ';
  161. $ Con = iconv ('gbk', 'utf-8', file_get_contents ($ params ['URL']);
  162. Preg_match ('/<\/TBODY> <\/TABLE> (.*)

    /S', $ con, $ arr );

  163. $ Result = strip_tags ($ arr [1],'
    ');
  164. $ Replace_arr1 = array ('', 'qq proxy: ', 'dn28. com ', 'qqip', 'qq proxy', 'qq proxy IP', 'proxy ip: ', 'Ip:', 'proxy IP ');
  165. $ Result = str_replace ($ replace_arr1, array (''), $ result );
  166. // Print_r ($ arr );
  167. $ ResArr = explode ('
    ', $ Result );
  168. // Print_r ($ resArr );
  169. Echo 'proxy starts batch verification, and the entire process takes several minutes. ';
  170. Unset ($ _ SESSION ['success _ arr']);
  171. Foreach ($ resArr as $ k => $ v ){
  172. $ NewRes [$ k] = parseProxyInfo ($ v );
  173. // Print_r ($ newRes [$ k]);
  174. /* Return ;*/
  175. $ Result = check_proxy_is_useful ('collect ', $ newRes [$ k]);
  176. $ Proxy_str_success = ''. $ newRes [$ k] ['IP']. ':'. $ newRes [$ k] ['port']. '@'. $ newRes [$ k] ['type']. 'Proxy verification successful! IP address: '. $ newRes [$ k] ['location']. '';
  177. $ Proxy_str_failed = ''. $ newRes [$ k] ['IP']. ':'. $ newRes [$ k] ['port']. '@'. $ newRes [$ k] ['type']. 'Proxy verification failed! IP address: '. $ newRes [$ k] ['location']. '';
  178. If ($ result! = False ){
  179. Echo $ proxy_str_success;
  180. $ _ SESSION ['success _ arr'] [] = $ success_arr [] = $ newRes [$ k];
  181. } Else {
  182. Echo $ proxy_str_failed;
  183. }
  184. Echo'
    ';
  185. }
  186. If (isset ($ success_arr) & count ($ success_arr)> 0 ){
  187. Save_success_proxy ($ success_arr );
  188. Echo'

    [Save the verified proxy to your local computer] [I want to see historical data]

    ';
  189. } Else {
  190. Echo'

    [I want to see historical data]

    ';
  191. }
  192. // Print_r ($ success_arr );
  193. }
  194. Function get_proxy_by_rule (){
  195. Global $ params, $ config;
  196. $ Result = $ proxy_ip = trim ($ params ['IP']);
  197. If ($ proxy_ip = ''){
  198. Echo 'Enter the IP address !! ';
  199. Return;
  200. }
  201. $ Replace_arr1 = array ('', 'qq proxy: ', 'dn28. com ', 'qqip', 'qq proxy', 'qq proxy IP', 'proxy ip: ', 'Ip:', 'proxy IP ');
  202. $ Result = str_replace ($ replace_arr1, array (''), $ result );
  203. $ ResArr = explode ("\ n", $ result );
  204. // Print_r ($ resArr );
  205. Echo 'proxy starts batch verification, and the entire process takes several minutes. ';
  206. Unset ($ _ SESSION ['success _ arr']);
  207. Foreach ($ resArr as $ k => $ v ){
  208. $ NewRes [$ k] = parseProxyInfo ($ v );
  209. // Print_r ($ newRes [$ k]);
  210. /* Return ;*/
  211. $ Result = check_proxy_is_useful ('collect ', $ newRes [$ k]);
  212. // Var_dump ($ result );
  213. $ Proxy_str_success = ''. $ newRes [$ k] ['IP']. ':'. $ newRes [$ k] ['port']. '@'. $ newRes [$ k] ['type']. 'Proxy verification successful! IP address: '. $ newRes [$ k] ['location']. '';
  214. $ Proxy_str_failed = ''. $ newRes [$ k] ['IP']. ':'. $ newRes [$ k] ['port']. '@'. $ newRes [$ k] ['type']. 'Proxy verification failed! IP address: '. $ newRes [$ k] ['location']. '';
  215. If ($ result! = False ){
  216. Echo $ proxy_str_success;
  217. $ _ SESSION ['success _ arr'] [] = $ success_arr [] = $ newRes [$ k];
  218. } Else {
  219. Echo $ proxy_str_failed;
  220. }
  221. Echo'
    ';
  222. }
  223. If (isset ($ success_arr) & count ($ success_arr)> 0 ){
  224. Save_success_proxy ($ success_arr );
  225. Echo'

    [Save to a php file] [Save the verified proxy to a local computer] [I want to see historical data]

    ';
  226. } Else {
  227. Echo'

    [I want to see historical data]

    ';
  228. }
  229. }
  230. Function save_success_proxy ($ success_arr ){
  231. Global $ config;
  232. Date_default_timezone_set ('prc ');
  233. $ Str = '';
  234. Foreach ($ success_arr as $ k => $ v ){
  235. $ Str. = $ v ['IP']. ':'. $ v ['port']. '@'. $ v ['type']. ';'. $ v ['location']. "\ n ";
  236. }
  237. $ Fp = fopen ($ config ['root _ path']. '/success_proxy/'. date ('ymdhi'). '. log', 'A + ');
  238. Fwrite ($ fp, $ str );
  239. Fclose ($ fp );
  240. Unset ($ str );
  241. }
  242. ?>

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.