Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Conenct to database
- define ('SEARCH_URL_PREFIX', 'http://na.aiononline.com/livestatus/character-legion/search?serverID=2&charID=');
- require_once('parallelcurl.php');
- set_time_limit(1999999999999999);
- $time_start = microtime(true);
- $servername = "localhost";
- $username = "root";
- $password = "";
- $database = "aionranks";
- // Create connection
- $conn = new mysqli($servername, $username, $password,$database);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT playerid FROM ignoreplayerids";
- $ignoreids = mysqli_query($conn, $sql);
- if (mysqli_num_rows($ignoreids) > 0) {
- // output data of each row
- echo "ignoreIds: <br>";
- while($row = mysqli_fetch_assoc($ignoreids)) {
- //echo "id: " . $row["playerid"]."<br>";
- }
- }
- if (isset($argv[1])) {
- $max_requests = $argv[1];
- } else {
- $max_requests = 100;
- }
- $curl_options = array(
- CURLOPT_SSL_VERIFYPEER => FALSE,
- CURLOPT_SSL_VERIFYHOST => FALSE,
- CURLOPT_USERAGENT, 'Parallel Curl test script',
- );
- $parallel_curl = new ParallelCurl($max_requests, $curl_options);
- //ob_start();
- //for($id=789720; $id<78925; $id=$id+1){
- for($id=238644; $id<2000000; $id=$id+1){
- $search = '';
- $search_url = SEARCH_URL_PREFIX.''.$id;
- $parallel_curl->startRequest($search_url, 'on_request_done',$id);
- }
- //ob_flush();
- // This should be called when you need to wait for the requests to finish.
- // This will automatically run on destruct of the ParallelCurl object, so the next line is optional.
- $parallel_curl->finishAllRequests();
- function on_request_done($content, $url, $ch,$id) {
- global $conn;
- //echo $content;
- $playerNameRegx = '/<\/em> .*?<\/span>/';
- if ( preg_match($playerNameRegx, $content, $list) ){
- $playerName = get_string_between($list[0],'</em> ','<\/span>');
- echo $id.",";
- //echo $playerName;
- //create table playerIds (playerId int);
- //create table ignorePlayerIds (playerId int);
- $sql = "insert into playerIds (playerId) values ('$id')";
- if ($conn->query($sql) === TRUE) {
- //echo "New record created successfully";
- } else {
- echo "<br><br>";
- echo "Error: " . $sql . "<br>" . $conn->error;
- echo "<br><br>";echo "<br><br>";echo "<br><br>";echo "<br><br>";
- }
- }
- else {
- //print "no player";
- $sql = "insert into ignoreplayerids (playerId) values ('$id')";
- if ($conn->query($sql) === TRUE) {
- //echo "New record created successfully";
- } else {
- echo "<br><br>";
- echo "Error: " . $sql . "<br>" . $conn->error;
- echo "<br><br>";echo "<br><br>";echo "<br><br>";echo "<br><br>";
- }
- }
- $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if ($httpcode !== 200) {
- print "Fetch error $httpcode for '$url'\n";
- return;
- }
- }
- function get_string_between($string, $start, $end){
- $string = ' ' . $string;
- $ini = strpos($string, $start);
- if ($ini == 0) return '';
- $ini += strlen($start);
- $len = strpos($string, $end, $ini) - $ini;
- return substr($string, $ini, $len);
- }
- $time_end = microtime(true);
- $time = $time_end - $time_start;
- echo "<br /><br /> runtime".round($time,2) . " s";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement