Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. while (true) {
  4.    
  5.     $file = '/home/kimse/Games/StarWarsGalaxies/profiles/inckie/Basilisk/281477446131588_chatlog.txt';
  6.  
  7.     $firstline = false;
  8.     if ($handle = fopen($file, 'c+')) {
  9.         if (!flock($handle, LOCK_EX)) {
  10.             fclose($handle);
  11.             continue;
  12.         }
  13.         $offset = 0;
  14.         $len    = filesize($file);
  15.         while (($line = fgets($handle, 4096)) !== false) {            
  16.            
  17.             if (!$firstline) {
  18.                 $firstline = $line;
  19.                 $offset    = strlen($firstline);
  20.                 continue;
  21.             }
  22.             $pos = ftell($handle);
  23.             fseek($handle, $pos - strlen($line) - $offset);
  24.             fputs($handle, $line);
  25.             fseek($handle, $pos);
  26.         }
  27.         fflush($handle);
  28.         ftruncate($handle, ($len - $offset));
  29.         flock($handle, LOCK_UN);
  30.         fclose($handle);
  31.     }
  32.  
  33.     echo $firstline;
  34.    
  35.     sleep(1); // Sleep 1 second
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement