original_string: public function tail($filepath, $lines = 1) {
  
          $f = @fopen($filepath, "rb");
          if ($f === false) return false;
  
          else $buffer = ($lines < 2 ? 64 : ($lines < 10 ? 512 : 4096));
  
          fseek($f, -1, SEEK_END);
          if (fread($f, 1) != "\n") $lines -= 1;
  
          // Start reading
          $output = '';
          $chunk = '';
          // While we would like more
          while (ftell($f) > 0 && $lines >= 0) {
              // Figure out how far back we should jump
              $seek = min(ftell($f), $buffer);
              // Do the jump (backwards, relative to where we are)
              fseek($f, -$seek, SEEK_CUR);
              // Read a chunk and prepend it to our output
              $output = ($chunk = fread($f, $seek)) . $output;
              // Jump back to where we started reading
              fseek($f, -mb_strlen($chunk, '8bit'), SEEK_CUR);
              // Decrease our line counter
              $lines -= substr_count($chunk, "\n");
          }
          // While we have too many lines
          // (Because of buffer size we might have read too many)
          while ($lines++ < 0) {
              // Find first newline and remove all text before that
              $output = substr($output, strpos($output, "\n") + 1);
          }
          // Close file and return
          fclose($f);
  
          return trim($output);
      }
code: public function tail($filepath, $lines = 1) {
  
          $f = @fopen($filepath, "rb");
          if ($f === false) return false;
  
          else $buffer = ($lines < 2 ? 64 : ($lines < 10 ? 512 : 4096));
  
          fseek($f, -1, SEEK_END);
          if (fread($f, 1) != "\n") $lines -= 1;
  
          // Start reading
          $output = '';
          $chunk = '';
          // While we would like more
          while (ftell($f) > 0 && $lines >= 0) {
              // Figure out how far back we should jump
              $seek = min(ftell($f), $buffer);
              // Do the jump (backwards, relative to where we are)
              fseek($f, -$seek, SEEK_CUR);
              // Read a chunk and prepend it to our output
              $output = ($chunk = fread($f, $seek)) . $output;
              // Jump back to where we started reading
              fseek($f, -mb_strlen($chunk, '8bit'), SEEK_CUR);
              // Decrease our line counter
              $lines -= substr_count($chunk, "\n");
          }
          // While we have too many lines
          // (Because of buffer size we might have read too many)
          while ($lines++ < 0) {
              // Find first newline and remove all text before that
              $output = substr($output, strpos($output, "\n") + 1);
          }
          // Close file and return
          fclose($f);
  
          return trim($output);
      }
code_tokens: public function tail ( $ filepath , $ lines = 1 ) { $ f = @ fopen ( $ filepath , "rb" ) ; if ( $ f === false ) return false ; else $ buffer = ( $ lines < 2 ? 64 : ( $ lines < 10 ? 512 : 4096 ) ) ; fseek ( $ f , - 1 , SEEK_END ) ; if ( fread ( $ f , 1 ) != "\n" ) $ lines -= 1 ; // Start reading $ output = '' ; $ chunk = '' ; // While we would like more while ( ftell ( $ f ) > 0 && $ lines >= 0 ) { // Figure out how far back we should jump $ seek = min ( ftell ( $ f ) , $ buffer ) ; // Do the jump (backwards, relative to where we are) fseek ( $ f , - $ seek , SEEK_CUR ) ; // Read a chunk and prepend it to our output $ output = ( $ chunk = fread ( $ f , $ seek ) ) . $ output ; // Jump back to where we started reading fseek ( $ f , - mb_strlen ( $ chunk , '8bit' ) , SEEK_CUR ) ; // Decrease our line counter $ lines -= substr_count ( $ chunk , "\n" ) ; } // While we have too many lines // (Because of buffer size we might have read too many) while ( $ lines ++ < 0 ) { // Find first newline and remove all text before that $ output = substr ( $ output , strpos ( $ output , "\n" ) + 1 ) ; } // Close file and return fclose ( $ f ) ; return trim ( $ output ) ; }
docstring: Optimized way to get just the last few entries of a log file
  
  @param string $filepath
  @param int $lines
  @return bool|string
docstring_tokens: Optimized way to get just the last few entries of a log file