Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- while (true) {
- $file = '/home/kimse/Games/StarWarsGalaxies/profiles/inckie/Basilisk/281477446131588_chatlog.txt';
- $firstline = false;
- if ($handle = fopen($file, 'c+')) {
- if (!flock($handle, LOCK_EX)) {
- fclose($handle);
- continue;
- }
- $offset = 0;
- $len = filesize($file);
- while (($line = fgets($handle, 4096)) !== false) {
- if (!$firstline) {
- $firstline = $line;
- $offset = strlen($firstline);
- continue;
- }
- $pos = ftell($handle);
- fseek($handle, $pos - strlen($line) - $offset);
- fputs($handle, $line);
- fseek($handle, $pos);
- }
- fflush($handle);
- ftruncate($handle, ($len - $offset));
- flock($handle, LOCK_UN);
- fclose($handle);
- }
- echo $firstline;
- sleep(1); // Sleep 1 second
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement