Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. $start_sec = date('U');
  2. do{
  3. LOG::Write_to_log('cycle start');
  4. $current_sec = date('U');
  5. $responses = multirequest($urls);
  6. save_resp($responses);
  7. }
  8. while
  9. ($current_sec != $start_sec + 1);
  10. LOG::Write_to_log('cycle start');
  11.  
  12. function multirequest($urls)
  13. {
  14.  
  15. $multi = curl_multi_init();
  16. $handles = [];
  17. $htmls = [];
  18.  
  19.  
  20. for($i=0; $i<count($urls);$i++)
  21. {
  22. $ch = curl_init($urls[$i]);
  23. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  24. curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  25. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
  26. //curl_setopt($ch, CURLOPT_PROXY, '1.2.3.4:80');
  27. curl_multi_add_handle($multi, $ch);
  28. array_push($handles, $ch);
  29. }
  30.  
  31. do {
  32. $mrc = curl_multi_exec($multi, $active);
  33. } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  34. while ($active && $mrc == CURLM_OK)
  35. {
  36. if (curl_multi_select($multi) == -1)
  37. {
  38. usleep(1);
  39. }
  40. do
  41. {
  42. $mrc = curl_multi_exec($multi, $active);
  43. }while($mrc == CURLM_CALL_MULTI_PERFORM);
  44. }
  45.  
  46. foreach($handles as $channel)
  47. {
  48. $html = curl_multi_getcontent($channel);
  49. $htmls[] = $html;
  50. curl_multi_remove_handle($multi, $channel);
  51. }
  52. curl_multi_close($multi);
  53. return $htmls;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement