PHPackages                             bcremer/line-reader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bcremer/line-reader

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bcremer/line-reader
===================

Read large files line by line in a memory efficient (constant) way.

1.3.0(3y ago)301.6M↓24.6%64MITPHPPHP ^7.4 || ^8.0

Since Aug 5Pushed 3y ago3 watchersCompare

[ Source](https://github.com/bcremer/LineReader)[ Packagist](https://packagist.org/packages/bcremer/line-reader)[ RSS](/packages/bcremer-line-reader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (5)Versions (12)Used By (4)

LineReader
==========

[](#linereader)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bafd5ceeca7cb9e5ab86381748c90f4bd66acd8ef5bddc467014e1c542b3b8c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626372656d65722f6c696e652d7265616465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bcremer/line-reader)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://github.com/bcremer/LineReader/workflows/Build/badge.svg)](https://github.com/bcremer/LineReader/actions?query=workflow%3ABuild)

LineReader is a library to read large files line by line in a memory efficient (constant) way.

Install
-------

[](#install)

Via Composer

```
$ composer require bcremer/line-reader
```

Usage
-----

[](#usage)

Given we have a textfile (`some/file.txt`) with lines like:

```
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

```

Also let's assume the namespace is imported to keep the examples dense:

```
use Bcremer\LineReader\LineReader;

```

### Read forwards

[](#read-forwards)

```
foreach (LineReader::readLines('some/file.txt') as $line) {
    echo $line . "\n"
}
```

The output will be:

```
Line 1
Line 2
Line 3
Line 4
Line 5
...

```

To set an offset or a limit use the `\LimitIterator`:

```
$lineGenerator = LineReader::readLines('some/file.txt');
$lineGenerator = new \LimitIterator($lineGenerator, 2, 5);
foreach ($lineGenerator as $line) {
    echo $line . "\n"
}
```

Will output line 3 to 7

```
Line 3
Line 4
Line 5
Line 6
Line 7

```

### Read backwards

[](#read-backwards)

```
foreach (LineReader::readLinesBackwards('some/file.txt') as $line) {
    echo $line;
}
```

```
Line 10
Line 9
Line 8
Line 7
Line 6
...

```

Example: Read the last 5 lines in forward order:

```
$lineGenerator = LineReader::readLinesBackwards('some/file.txt');
$lineGenerator = new \LimitIterator($lineGenerator, 0, 5);

$lines = array_reverse(iterator_to_array($lineGenerator));
foreach ($line as $line) {
    echo $line;
}
```

```
Line 6
Line 7
Line 8
Line 9
Line 10

```

Testing
-------

[](#testing)

```
$ composer test
```

```
$ TEST_MAX_LINES=200000 composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~394 days

Recently: every ~473 days

Total

7

Last Release

1207d ago

Major Versions

0.2.0 → 1.0.02017-11-21

PHP version history (7 changes)0.1.0PHP ~5.6|~7.0

0.2.0PHP ~5.6|~7.0|~7.1

1.0.0PHP ~7.1|~7.2

1.0.1PHP ~7.1|~7.2|~7.3

1.1.0PHP ^7.3|^7.4|^8.0

1.2.0PHP ^7.3|^7.4|^8.0|^8.1

1.3.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0545dfa5917845b12373dfa688658be444a3e611aae930cc37840cf8f4acd01d?d=identicon)[bcremer](/maintainers/bcremer)

---

Top Contributors

[![bcremer](https://avatars.githubusercontent.com/u/55820?v=4)](https://github.com/bcremer "bcremer (50 commits)")[![mitelg](https://avatars.githubusercontent.com/u/6985627?v=4)](https://github.com/mitelg "mitelg (4 commits)")[![teiling88](https://avatars.githubusercontent.com/u/4624237?v=4)](https://github.com/teiling88 "teiling88 (1 commits)")

---

Tags

large-fileslinereaderphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bcremer-line-reader/health.svg)

```
[![Health](https://phpackages.com/badges/bcremer-line-reader/health.svg)](https://phpackages.com/packages/bcremer-line-reader)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
