PHPackages                             fruivita/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. [File &amp; Storage](/categories/file-storage)
4. /
5. fruivita/line-reader

ActiveLibrary[File &amp; Storage](/categories/file-storage)

fruivita/line-reader
====================

Read large files, line by line, without causing memory overflow for Laravel applications

v1.0.0(4y ago)03.0k[1 PRs](https://github.com/fruivita/line-reader/pulls)MITPHPPHP ^8.0

Since May 10Pushed 2y agoCompare

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

READMEChangelog (1)Dependencies (10)Versions (4)Used By (0)

File Reader for Laravel applications
====================================

[](#file-reader-for-laravel-applications)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f2488e850ac8bbf8b4f182ef7c779ad21837c721ea8d013223f5dc8466a70427/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66727569766974612f6c696e652d7265616465723f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/fruivita/line-reader)[![GitHub Release Date](https://camo.githubusercontent.com/581fdc199eb41376c255a0ab5bf4ac65f8f5dcef3e4ddb1e259e9bc7f978c7c7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f66727569766974612f6c696e652d7265616465723f6c6f676f3d676974687562)](/../../releases)[![GitHub last commit (branch)](https://camo.githubusercontent.com/3cb62214a687ced26e88902e7bbe9361bec15e757f619a0a18ff0e4fc4a9d605/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f66727569766974612f6c696e652d7265616465722f312e783f6c6f676f3d676974687562)](/../../commits/1.x)[![GitHub Tests Action Status](https://camo.githubusercontent.com/cb8e8293ba35723fa67abe91026ff0d0cdff1c12fc11c3bc2f51fd4a2cce5cfb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f66727569766974612f6c696e652d7265616465722f556e6974253230616e642532304665617475726525323074657374732f312e783f6c6162656c3d7465737473266c6f676f3d676974687562)](/../../actions/workflows/tests.yml?query=branch%3A1.x)[![Test Coverage](https://camo.githubusercontent.com/c03e0e0dd3d57d1a4c6525e955d083e9708b17d96c42f6d658e171cd99751f7b/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f33383165373639393130643337343064636366652f746573745f636f766572616765)](https://codeclimate.com/github/fruivita/line-reader/test_coverage)[![Maintainability](https://camo.githubusercontent.com/8b43f95624b5477ab6c869169e812416b016bc49899011de68999e3df98a9592/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f33383165373639393130643337343064636366652f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/fruivita/line-reader/maintainability)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/e75b2f63fc0b8375d4db5f6badb0d3dbde2811301ee076daddf71a795d7b0aab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f66727569766974612f6c696e652d7265616465722f537461746963253230416e616c797369732f312e783f6c6162656c3d636f64652532307374796c65266c6f676f3d676974687562)](/../../actions/workflows/static.yml?query=branch%3A1.x)[![GitHub issues](https://camo.githubusercontent.com/ad01b5509f713cf08fe43381aa4d53d7125db68e01fd7b075e30bf337b73bab0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f66727569766974612f6c696e652d7265616465723f6c6f676f3d676974687562)](/../../issues)[![GitHub repo size](https://camo.githubusercontent.com/e74e486f4e0ce003bb0b0e14d8270b03ca30463b661220ddb43e8490b5572e42/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f66727569766974612f6c696e652d7265616465723f6c6f676f3d676974687562)](https://camo.githubusercontent.com/e74e486f4e0ce003bb0b0e14d8270b03ca30463b661220ddb43e8490b5572e42/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f66727569766974612f6c696e652d7265616465723f6c6f676f3d676974687562)[![Packagist Total Downloads](https://camo.githubusercontent.com/a94d5577e8f5b86ff82992f6cc88c2e0679e4630504999742d7912a3c4f97762/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f66727569766974612f6c696e652d7265616465723f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/fruivita/line-reader)[![GitHub](https://camo.githubusercontent.com/a743b252af415553d9dd799e2f36131cd6d5e59b6484e563e75690a5ea4357b9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f66727569766974612f6c696e652d7265616465723f6c6f676f3d676974687562)](../LICENSE.md)

This package, for **[Laravel](https://laravel.com/docs)** applications, allows you to read the contents of huge files without killing your server, that is, without having to load all the contents at once in memory causing an ***out-of-memory errors***.

The strategy used here is to read the contents of the file, line by line, optimizing the use of server resources and, most importantly, in an efficient way.

It is also possible to paginate the contents of the file, again, without having to load it entirely into memory, except the page itself.

```
use FruiVita\LineReader\Facades\LineReader;

$generator = LineReader::readLines($file_path);

// or

$length_aware_paginator = LineReader::readPaginatedLines($file_path, $per_page, $page);
```

---

Table of Contents
-----------------

[](#table-of-contents)

1. [Notes](#notes)
2. [Prerequisites](#prerequisites)
3. [Installation](#installation)
4. [How it works](#how-it-works)
5. [Testing and Continuous Integration](#testing-and-continuous-integration)
6. [Changelog](#changelog)
7. [Contributing](#contributing)
8. [Code of conduct](#code-of-conduct)
9. [Security Vulnerabilities](#security-vulnerabilities)
10. [Support and Updates](#support-and-updates)
11. [Roadmap](#roadmap)
12. [Credits](#credits)
13. [Thanks](#thanks)
14. [License](#license)

---

Notes
-----

[](#notes)

⭐ Internally, this package reads the file contents using php's **[SplFileObject](https://www.php.net/manual/en/class.splfileobject.php)** and **[Generators](https://www.php.net/manual/en/language.generators.overview.php)** classes. In the specific case of pagination, the **[LimitIterator](https://www.php.net/manual/en/class.limititerator.php)** class is used to delimit the beginning and end of the content to be read.

❤️ Heavily inspired by the [bcremer/LineReader](https://github.com/bcremer/LineReader) package.

⬆️ [Back](#table-of-contents)

Prerequisites
-------------

[](#prerequisites)

1. PHP dependencies

    PHP ^8.0

    [Extensions](https://getcomposer.org/doc/03-cli.md#check-platform-reqs)

    ```
    composer check-platform-reqs
    ```
2. [GitHub Package Dependencies](/../../network/dependencies)

⬆️ [Back](#table-of-contents)

Installation
------------

[](#installation)

1. Install via **[composer](https://getcomposer.org/)**:

    ```
    composer require fruivita/line-reader
    ```
2. Optionally publish the translations

    ```
    php artisan vendor:publish --provider='FruiVita\LineReader\LineReaderServiceProvider' --tag='lang'
    ```

    The strings available for translation are as follows. Change them as needed.

    ```
    {
        "The file entered could not be read": "The file entered could not be read"
    }
    ```

    > This package already has translations for **en** and **pt-br**.

⬆️ [Back](#table-of-contents)

How it works
------------

[](#how-it-works)

1. Reading a file line by line.

    ```
    use FruiVita\LineReader\Facades\LineReader;

    public function example()
    {
        foreach (LineReader::readLines($file_path) as $key => $line)
        {
            // $key is 0 when reading the 1st line, 1 when reading the 2nd line, and so on.
            // $line is a string with the contents of the line.
        }
    }
    ```

    LineReader exposes the following method to read the file line by line:

    ✏️ **readLines**

    ```
    use FruiVita\LineReader\Facades\LineReader;

    /**
     * @param string $file_path full path of the file to be read
     *
     * @throws \FruiVita\LineReader\Exceptions\FileNotReadableException
     *
     * @return \Generator
     */
    LineReader::readLines(string $file_path);
    ```

    🚨 **Exceptions**:

    - **readLines** throws **\\FruiVita\\LineReader\\Exceptions\\FileNotReadableException** if don't have read permission on the file or it can't be found
2. Reading the file by page.

    ```
    use FruiVita\LineReader\Facades\LineReader;

    public function example()
    {
        $per_page = 15;
        $page = 2;

        $length_aware_paginator = LineReader::readPaginatedLines(string $file_path, int $per_page, int $page);

        // The index of the items in the collection respects their position in the file using a zero-based index,
        // that is, in the example above the 1st item on page 2 will have index 15, since it is the 16th line of
        // the file and the last item on page 2 will have index 29, since it is the 30th line of the file.
    }
    ```

    LineReader exposes the following method to read the file by page:

    ✏️ **readPaginatedLines**

    ```
    use FruiVita\LineReader\Facades\LineReader;

    /**
     * @param string $file_path full path of the file to be read
     * @param int    $per_page
     * @param int    $page
     * @param string $page_name
     *
     * @throws \FruiVita\LineReader\Exceptions\FileNotReadableException
     * @throws \InvalidArgumentException
     *
     * @return \Illuminate\Pagination\LengthAwarePaginator
     */
    LineReader::readPaginatedLines(string $file_path, int $per_page, int $page, string $page_name = 'page');
    ```

    🚨 **Exceptions**:

    - **readPaginatedLines** throws **\\FruiVita\\LineReader\\Exceptions\\FileNotReadableException** if don't have read permission on the file or it can't be found
    - **readPaginatedLines** throws **\\InvalidArgumentException** if per\_page or page is less than 1

⬆️ [Back](#table-of-contents)

Testing and Continuous Integration
----------------------------------

[](#testing-and-continuous-integration)

```
composer analyse
composer test
composer coverage
```

⬆️ [Back](#table-of-contents)

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed in each version.

⬆️ [Back](#table-of-contents)

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for more details on how to contribute.

⬆️ [Back](#table-of-contents)

Code of conduct
---------------

[](#code-of-conduct)

To ensure that everyone is welcome to contribute to this open-source project, please read and follow the [Code of Conduct](CODE_OF_CONDUCT.md).

⬆️ [Back](#table-of-contents)

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please see [security policy](/../../security/policy) how to report security vulnerabilities or flaws.

⬆️ [Back](#table-of-contents)

Support and Updates
-------------------

[](#support-and-updates)

The latest version will receive support and updates whenever the need arises. The others will receive updates for 06 months after being replaced by a new version and then discontinued.

VersionPHPReleaseEnd of Life1.0^8.009-05-2022dd-mm-yyyy🐛 Found a bug?!?! Open an **[issue](/../../issues/new?assignees=fcno&labels=bug%2Ctriage&template=bug_report.yml&title=%5BA+concise+title+for+the+bug%5D)**.

⬆️ [Back](#table-of-contents)

Roadmap
-------

[](#roadmap)

> ✨ Any new ideas?!?! Start a **[discussion](https://github.com/orgs/fruivita/discussions/new?category=ideas&title=%5BLineReader%5D)**.

The following list contains identified and approved improvement needs that will be implemented in the first window of opportunity.

- n/a

⬆️ [Back](#table-of-contents)

Credits
-------

[](#credits)

- [Fábio Cassiano](https://github.com/fcno)
- [All Contributors](/../../contributors)

⬆️ [Back](#table-of-contents)

Thanks
------

[](#thanks)

👋 Thanks to the people and organizations below for donating their time to build the open-source projects that were used in this package.

- ❤️ [Laravel](https://github.com/laravel) for the packages:

    - [illuminate/collections](https://github.com/illuminate/collections)
    - [illuminate/pagination](https://github.com/illuminate/pagination)
    - [illuminate/support](https://github.com/illuminate/support)
- ❤️ [Orchestra Platform](https://github.com/orchestral) for the package [orchestral/testbench](https://github.com/orchestral/testbench)
- ❤️ [FriendsOfPHP](https://github.com/FriendsOfPHP) for the package [FriendsOfPHP/PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
- ❤️ [Nuno Maduro](https://github.com/nunomaduro) for the package [nunomaduro/larastan](https://github.com/nunomaduro/larastan)
- ❤️ [PEST](https://github.com/pestphp) for the packages:

    - [pestphp/pest](https://github.com/pestphp/pest)
    - [pestphp/pest-plugin-laravel](https://github.com/pestphp/pest-plugin-laravel)
- ❤️ [Sebastian Bergmann](https://github.com/sebastianbergmann) for the package [sebastianbergmann/phpunit](https://github.com/sebastianbergmann/phpunit)
- ❤️ [PHPStan](https://github.com/phpstan) for the packages:

    - [phpstan/phpstan](https://github.com/phpstan/phpstan)
    - [phpstan/phpstan-deprecation-rules](https://github.com/phpstan/phpstan-deprecation-rules)
- ❤️ [ergebnis](https://github.com/ergebnis) for the package [ergebnis/composer-normalize](https://github.com/ergebnis/composer-normalize)
- ❤️ [Shivam Mathur](https://github.com/shivammathur) for the Github Action [shivammathur/setup-php](https://github.com/shivammathur/setup-php)
- ❤️ [GP](https://github.com/paambaati) for the Github Action [paambaati/codeclimate-action](https://github.com/paambaati/codeclimate-action)
- ❤️ [Stefan Zweifel](https://github.com/stefanzweifel) for the Github Actions:

    - [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action)
    - [stefanzweifel/changelog-updater-action](https://github.com/stefanzweifel/changelog-updater-action)

💸 Some of these people or organizations have some products/services that can be purchased. If you can help them by buying one of them or becoming a sponsor, even for a short period, you will help the entire **open-source** community to continue developing solutions for everyone.

⬆️ [Back](#table-of-contents)

License
-------

[](#license)

The MIT License (MIT). Please see the **[License File](../LICENSE.md)** for more information.

⬆️ [Back](#table-of-contents)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

1468d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/59084dba6352f226a5807e548270a92d5943f1ee8f97931e7a7ccde4142bd71b?d=identicon)[fcno](/maintainers/fcno)

---

Top Contributors

[![fcno](https://avatars.githubusercontent.com/u/71986962?v=4)](https://github.com/fcno "fcno (62 commits)")

---

Tags

big-filesfile-readerlaravelline-readerphpphplaravelreaderfile readerfruivitaline-reader

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[madnest/madzipper

Easier zip file handling for Laravel applications.

1382.3M6](/packages/madnest-madzipper)[sopamo/laravel-filepond

Laravel backend module for filepond uploads

215272.2k3](/packages/sopamo-laravel-filepond)[soarecostin/file-vault

192195.0k](/packages/soarecostin-file-vault)[brainstud/file-vault

1231.6k](/packages/brainstud-file-vault)

PHPackages © 2026

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