jotaelesalinas/php-rwgen

This package is abandoned and no longer maintained. The author suggests using the jotaelesalinas/php-data-streams package instead.

Read and write huge CSV, JSON, XML and Excel streams in PHP without running out of memory.

Maintainers

Package info

github.com/jotaelesalinas/php-generators

Homepage

pkg:composer/jotaelesalinas/php-rwgen

Statistics

Installs: 200

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.5.1 2018-11-15 22:15 UTC

This package is auto-updated.

Last update: 2026-06-09 18:47:30 UTC


README

License CI

php-data-streams is a PHP streaming library for reading and writing large CSV, JSON, XML, XLSX, KML, HTTP and database-backed records without loading everything into memory.

It is designed for data pipelines, import/export jobs, CLI tools and integrations where you want small, explicit reader and writer abstractions instead of heavyweight framework-specific layers.

What it solves

  • Process large files and responses record by record.
  • Keep memory usage predictable while iterating through data.
  • Compose simple readers and writers around generators and iterables.
  • Reuse a shared contract across multiple formats.

How This Repository Is Organized

This project is a monorepo split into several smaller packages.

That means the repository contains multiple packages in one place, but you do not need to install all of them. Install only the package or packages you actually need.

For example:

  • If you only work with CSV files, install the CSV package.
  • If you only need JSON Lines, install the JSON package.
  • If you want the shared reader and writer interfaces for your own code, install the core package.

Packages

  • core for the shared Reader and Writer contracts.
  • csv for CSV and TSV readers and writers.
  • json for JSON, JSON arrays and NDJSON / JSON Lines.
  • xml for lazy XML readers and streaming XML writers.
  • kml for KML output built on XML.
  • pdo for database cursor helpers.
  • http for line and page-oriented HTTP streams.
  • excel for minimal XLSX sheet readers.

Quick Example

use JLSalinas\DataStreams\Csv\CsvReader;

$reader = new CsvReader(__DIR__ . '/customers.csv');

foreach ($reader as $customer) {
    echo $customer['name'] . PHP_EOL;
}

Installation

Install the package you need via Composer. For example, to work with CSV files:

composer require jotaelesalinas/php-data-streams-csv

If you want to work with JSON Lines:

composer require jotaelesalinas/php-data-streams-json

If you want to build your own reader or writer and only need the shared interfaces:

composer require jotaelesalinas/php-data-streams-core

You can also install more than one package if your project needs them.

Example Usage

CSV reader

use JLSalinas\DataStreams\Csv\CsvReader;

$reader = new CsvReader(__DIR__ . '/customers.csv');

foreach ($reader as $customer) {
    echo $customer['name'] . PHP_EOL;
}

CSV writer

use JLSalinas\DataStreams\Csv\CsvWriter;

$writer = new CsvWriter(__DIR__ . '/export.csv');
$writer->write(['name' => 'Ada', 'email' => 'ada@example.com']);
$writer->write(['name' => 'Grace', 'email' => 'grace@example.com']);
$writer->close();

JSON reader

use JLSalinas\DataStreams\Json\JsonReader;

$reader = new JsonReader(__DIR__ . '/events.ndjson');

foreach ($reader as $event) {
    var_dump($event);
}

Typical Use Cases

  • CSV/TSV imports and exports.
  • JSON Lines ingestion and generation.
  • XML feeds and document-to-record transforms.
  • XLSX sheet reading in long-running jobs.
  • KML generation from geospatial records.
  • Streaming database results and HTTP responses.

Project Status

This repository is the home of independently publishable packages. The codebase has been renamed and reorganized around the JLSalinas\DataStreams namespace, and each package README documents its own behavior and usage.