Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

jimenezmaximiliano/php-tail-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Tail File

Latest Version Maintenance Coverage

Efficiently tail a file from PHP - Reads the last x number of lines of a file (similar to Unix's tail command)

  • Great performance
  • It doesn't load the whole file to memory
  • Skips trailing new lines and empty lines
  • No dependencies
  • Tested on Linux, Windows and macOS
  • Compatible with PHP 7.4 and ^8

Usually used to read the last lines of:

  • CSV files
  • Log files
  • JSON files
  • text files

Installation

composer require jimenezmaximiliano/php-tail-file

Usage

$numberOfLines = 2;
$filePath = realpath("file.log");

$lines = Tail::tail($filePath, $numberOfLines);

// ["line 30", "line 31"]