fruivita/line-reader
Composer 安装命令:
composer require fruivita/line-reader
包简介
Read large files, line by line, without causing memory overflow for Laravel applications
README 文档
README
This package, for Laravel 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
Notes
⭐ Internally, this package reads the file contents using php's SplFileObject and Generators classes. In the specific case of pagination, the LimitIterator class is used to delimit the beginning and end of the content to be read.
❤️ Heavily inspired by the bcremer/LineReader package.
⬆️ Back
Prerequisites
-
PHP dependencies
PHP ^8.0
composer check-platform-reqs
⬆️ Back
Installation
-
Install via composer:
composer require fruivita/line-reader
-
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
How it works
-
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
-
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
Testing and Continuous Integration
composer analyse
composer test
composer coverage
⬆️ Back
Changelog
Please see CHANGELOG for more information on what has changed in each version.
⬆️ Back
Contributing
Please see CONTRIBUTING for more details on how to contribute.
⬆️ Back
Code of conduct
To ensure that everyone is welcome to contribute to this open-source project, please read and follow the Code of Conduct.
⬆️ Back
Security Vulnerabilities
Please see security policy how to report security vulnerabilities or flaws.
⬆️ Back
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.
| Version | PHP | Release | End of Life |
|---|---|---|---|
| 1.0 | ^8.0 | 09-05-2022 | dd-mm-yyyy |
🐛 Found a bug?!?! Open an issue.
⬆️ Back
Roadmap
✨ Any new ideas?!?! Start a discussion.
The following list contains identified and approved improvement needs that will be implemented in the first window of opportunity.
- n/a
⬆️ Back
Credits
⬆️ Back
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 for the packages:
-
❤️ Orchestra Platform for the package orchestral/testbench
-
❤️ FriendsOfPHP for the package FriendsOfPHP/PHP-CS-Fixer
-
❤️ Nuno Maduro for the package nunomaduro/larastan
-
❤️ PEST for the packages:
-
❤️ Sebastian Bergmann for the package sebastianbergmann/phpunit
-
❤️ PHPStan for the packages:
-
❤️ ergebnis for the package ergebnis/composer-normalize
-
❤️ Shivam Mathur for the Github Action shivammathur/setup-php
-
❤️ GP for the Github Action paambaati/codeclimate-action
-
❤️ Stefan Zweifel for the Github Actions:
💸 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
License
The MIT License (MIT). Please see the License File for more information.
⬆️ Back
fruivita/line-reader 适用场景与选型建议
fruivita/line-reader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.98k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「reader」 「file-reader」 「fruivita」 「line-reader」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fruivita/line-reader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fruivita/line-reader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fruivita/line-reader 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
laravel facade to read/write csv file
Just parse YAML content to array
Alfabank REST API integration
Simple PHP QR Code Reader / Decoder
CSS reader and writer with full CSS3 support, already supporting huge parts of the current CSS4 spec. It supports media queries, comments, value optimization and more... It offers full Unicode support and can handle also large CSS sources. Requires PHP 5.4+.
PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)
统计信息
- 总下载量: 2.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-05-10