PHPackages                             nekman/files - 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. nekman/files

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

nekman/files
============

TODO

1.1.0(3y ago)0637MITPHPPHP ^7.4||^8.0

Since May 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Ekman/php-files)[ Packagist](https://packagist.org/packages/nekman/files)[ RSS](/packages/nekman-files/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (9)Used By (0)

Files
=====

[](#files)

[![Build Status](https://camo.githubusercontent.com/4ae525e48c3517e30a07729706ed5b58629b22733faeb37c22c1c4075a193e66/68747470733a2f2f636972636c6563692e636f6d2f67682f456b6d616e2f7068702d66696c65732e7376673f7374796c653d737667)](https://app.circleci.com/pipelines/github/Ekman/php-files)[![Coverage Status](https://camo.githubusercontent.com/50e6477414bdd814753763e4d75020ad9c3463dc112408168d62c8ab84b6498f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f456b6d616e2f7068702d66696c65732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Ekman/php-files?branch=master)

When creating code that read and writes files I tend to utilize [`Generator`/`Traversable`/`iterable`](https://www.php.net/manual/en/language.generators.overview.php). No need to read entire files into memory, may as well process them line-by-line. Purely a win-win situation. This library contains code that I found myself writing over and over again. It is a very small and minimal library.

This library does not re-invent any wheels. It is basically just a wrapper for using [`fopen`](https://www.php.net/manual/en/function.fopen), [`fgets`](https://www.php.net/manual/en/function.fgets), [`fgetcsv`](https://www.php.net/manual/en/function.fgetcsv) and [`fclose`](https://www.php.net/manual/en/function.fclose)with [`Generator`](https://www.php.net/manual/en/language.generators.overview.php).

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

[](#installation)

Install with [Composer](https://getcomposer.org/):

```
composer require nekman/php-files
```

Usage
-----

[](#usage)

The library does not contain any classes that needs to be instantiated. It is just a couple of pure functions.

### Text files

[](#text-files)

To read and write ordinary text files:

```
use function Nekman\Files\file_read_lines;
use function Nekman\Files\file_write_lines;

# Reading a file
$it = file_read_lines("/path/to/my/file");
foreach ($it as $line) {
	// This is ready, line-by-line. The file is never read completely into memory at once.
	echo $line;
}

# Writing a file
file_write_lines("/path/to/my/file", ["line1", "line2"]);

# Writing a file using Generator
function my_generator(): iterable
{
	yield "line1";
	yield "line2";
}

file_write_lines("/path/to/my/file", my_generator());
```

### CSV files

[](#csv-files)

To read and write CSV files:

```
use function Nekman\Files\file_read_csv;
use function Nekman\Files\file_write_csv;

# Reading from a CSV
$it = file_read_csv("/path/to/csv");
foreach ($it as $row) {
	[$column1, $column2] = $row;
	echo "$column1,$column2";
}

# Writing a CSV file
file_write_csv("/path/to/csv", [["column1x", "column2x"], ["column1y", "column2y"]]);

# Writing a file using Generator
function my_generator(): iterable
{
	yield ["column1x", "column2x"];
	yield ["column1y", "column2y"];
}

file_write_csv("/path/to/my/file", my_generator());
```

Versioning
----------

[](#versioning)

This project complies with [Semantic Versioning](https://semver.org/).

Changelog
---------

[](#changelog)

For a complete list of changes, and how to migrate between major versions, see [releases page](https://github.com/Ekman/php-files/releases).

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~77 days

Recently: every ~115 days

Total

7

Last Release

1422d ago

Major Versions

0.0.3 → 1.0.02021-05-22

PHP version history (2 changes)0.0.1PHP ^7.4|^8.0

0.0.3PHP ^7.4||^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/568019?v=4)[Nils](/maintainers/NEkman)[@nekman](https://github.com/nekman)

---

Top Contributors

[![lindelius](https://avatars.githubusercontent.com/u/8205651?v=4)](https://github.com/lindelius "lindelius (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/nekman-files/health.svg)

```
[![Health](https://phpackages.com/badges/nekman-files/health.svg)](https://phpackages.com/packages/nekman-files)
```

PHPackages © 2026

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