Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. <?php
  2.  
  3. //Conenct to database
  4.  
  5.  
  6. require_once('parallelcurl.php');
  7. set_time_limit(1999999999999999);
  8. $time_start = microtime(true);
  9.  
  10. $servername = "localhost";
  11. $username = "root";
  12. $password = "";
  13. $database = "aionranks";
  14.  
  15. // Create connection
  16. $conn = new mysqli($servername, $username, $password,$database);
  17.  
  18. // Check connection
  19. if ($conn->connect_error) {
  20. die("Connection failed: " . $conn->connect_error);
  21. }
  22.  
  23. define ('SEARCH_URL_PREFIX', 'http://na.aiononline.com/livestatus/character-legion/search?serverID=2&charID=');
  24. // This function gets called back for each request that completes
  25. function on_request_done($content, $url, $ch,$id) {
  26.  
  27. global $conn;
  28.  
  29. //echo $content;
  30. $playerNameRegx = '/<\/em> .*?<\/span>/';
  31.  
  32. if ( preg_match($playerNameRegx, $content, $list) ){
  33. $playerName = get_string_between($list[0],'</em> ','<\/span>');
  34. echo $id.",";
  35.  
  36. //echo $playerName;
  37.  
  38. //create table playerIds (playerId int);
  39.  
  40.  
  41.  
  42. $sql = "insert into playerIds (playerId) values ('$id')";
  43.  
  44. //echo $sql;
  45.  
  46.  
  47. if ($conn->query($sql) === TRUE) {
  48. echo "New record created successfully";
  49. } else {
  50. echo "<br><br>";
  51. echo "Error: " . $sql . "<br>" . $conn->error;
  52. echo "<br><br>";echo "<br><br>";echo "<br><br>";echo "<br><br>";
  53. }
  54.  
  55.  
  56.  
  57. }
  58. else {
  59. //print "no player";
  60. }
  61.  
  62.  
  63. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  64. if ($httpcode !== 200) {
  65. print "Fetch error $httpcode for '$url'\n";
  66. return;
  67. }
  68.  
  69. }
  70.  
  71.  
  72.  
  73.  
  74. if (isset($argv[1])) {
  75. $max_requests = $argv[1];
  76. } else {
  77. $max_requests = 10;
  78. }
  79. $curl_options = array(
  80. CURLOPT_SSL_VERIFYPEER => FALSE,
  81. CURLOPT_SSL_VERIFYHOST => FALSE,
  82. CURLOPT_USERAGENT, 'Parallel Curl test script',
  83. );
  84. $parallel_curl = new ParallelCurl($max_requests, $curl_options);
  85. ob_start();
  86.  
  87. for($id=789720; $id<789730; $id=$id+1){
  88. $search = '';
  89. $search_url = SEARCH_URL_PREFIX.''.$id;
  90.  
  91. $parallel_curl->startRequest($search_url, 'on_request_done',$id);
  92.  
  93. }
  94. ob_flush();
  95. // This should be called when you need to wait for the requests to finish.
  96. // This will automatically run on destruct of the ParallelCurl object, so the next line is optional.
  97.  
  98.  
  99.  
  100. $parallel_curl->finishAllRequests();
  101.  
  102.  
  103. function get_string_between($string, $start, $end){
  104. $string = ' ' . $string;
  105. $ini = strpos($string, $start);
  106. if ($ini == 0) return '';
  107. $ini += strlen($start);
  108. $len = strpos($string, $end, $ini) - $ini;
  109. return substr($string, $ini, $len);
  110. }
  111.  
  112.  
  113. $time_end = microtime(true);
  114. $time = $time_end - $time_start;
  115. echo "<br /><br /> runtime".round($time,2) . " s";
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement