Advertisement
Guest User

Untitled

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