Ultra-fast, memory-efficient streaming Excel (.xlsx) and CSV exporter in pure PHP 8.2+ with zero external dependencies (< 16MB RAM for 100K+ rows).
Standard PHP spreadsheet libraries (such as phpoffice/phpspreadsheet) allocate heavyweight in-memory cell models, consuming 80MB to 300MB+ of RAM for large exports and frequently causing Out-Of-Memory (OOM) crashes in Docker containers and web workers.
LiteExport bypasses in-memory DOM allocations completely:
- Streams row-by-row directly into compressed OpenXML parts on disk using PHP Generators.
- Includes a pure PHP OpenXML Zip packager (
SimpleZip) utilizing nativezlib—runs without even requiringext-zip. - Memory usage stays strictly under 16MB regardless of dataset size (1,000 or 500,000 rows).
- Integrates seamlessly with
LiteORM::cursor()for end-to-end$O(1)$ memory database exports. -
CWE-1236 Formula Injection Mitigation: Automatically sanitizes dangerous spreadsheet trigger prefixes (
=,+,-,@,\t,\r) in CSV files.
composer require kzxl/lite-exportTo pull directly from the official GitHub repository without waiting for Packagist synchronization, add the VCS repository to your project's composer.json:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/kzxl/LiteExport.git"
}
],
"require": {
"kzxl/lite-export": "^1.1.0"
}
}Or configure via CLI:
composer config repositories.lite-export vcs https://github.com/kzxl/LiteExport.git
composer require kzxl/lite-export:^1.1.0For local development where changes should reflect immediately via symlink:
{
"repositories": [
{
"type": "path",
"url": "../libs/LiteExport",
"options": {
"symlink": true
}
}
],
"require": {
"kzxl/lite-export": "@dev"
}
}use LiteExport\Exporter;
// Export from array
$data = [
['id' => 1, 'name' => 'Alice Johnson', 'price' => 150.00],
['id' => 2, 'name' => 'Bob Smith', 'price' => 320.50],
];
Exporter::xlsx($data, '/path/to/report.xlsx', sheetName: 'Customers');
// Export from LiteORM database cursor with O(1) memory!
$usersCursor = $em->query(User::class)->cursor(); // Yields one row at a time
Exporter::xlsx($usersCursor, '/path/to/large_users_export.xlsx');use LiteExport\Exporter;
// Auto-prepends UTF-8 BOM so Microsoft Excel opens Vietnamese / Unicode without errors
Exporter::csv($usersCursor, '/path/to/export.csv');
// Or export directly to string
$csvString = Exporter::csv($data);composer test
# or
./vendor/bin/phpunitMIT License — see LICENSE for details.
Architected by Phong Vo (kzxl).