Advertisement
viamvadens

Untitled

Apr 23rd, 2021
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $start_date = strtotime('2021-04-23 00:00:00');
  5. $end_date = strtotime('2021-12-31 00:00:00');
  6.  
  7.  
  8. $fp = fopen(dirname(__FILE__) . "/test_actions.log", 'r');
  9. $cnt_total = 0; $cnt_unknown=0; $cnt_goal=0;
  10. $unique_ips = array();
  11. while(!feof($fp)){
  12.     $str = fgets($fp);
  13.     $cnt_total ++;
  14.     if(count(($p = explode("\t", $str))) < 5){
  15.         $cnt_unknown++;
  16.         continue;
  17.     }
  18.     list($date_time, $_, $remote_adr, $cmd) = $p;
  19.  
  20.     #echo $date_time . "\t" . date("Y-m-d H:i:s", strtotime($date_time)) . "\n";
  21.  
  22.     if($cnt_total > 100) #exit;
  23.  
  24.     if($cmd !== 'subscribe'){
  25.         continue;
  26.     }
  27.  
  28.     $date_time = strtotime($date_time);
  29.  
  30.     if($date_time < $start_date or $date_time > $end_date){
  31.         continue;
  32.     }
  33.  
  34.     $cnt_goal++;
  35.  
  36.     if(!isset($unique_ips[$remote_adr])){
  37.         $unique_ips[$remote_adr] = 0;
  38.     }
  39.  
  40.     $unique_ips[$remote_adr] ++;
  41.  
  42.     #print_r($p); exit;
  43.    #var_dump($str);
  44.    #break;
  45. }
  46. fclose($fp);
  47.  
  48. echo "Total lines processed: $cnt_total\n";
  49. echo "Total lines goal: $cnt_goal\n";
  50. if($cnt_unknown > 1){
  51.     echo " \t- unknown lines: $cnt_unknown\t!!!\n";
  52. }
  53.  
  54. echo "\n";
  55.  
  56. echo "Unique IPs: ". count(array_keys($unique_ips)) . "\n";
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement