php_excel

June 5, 2026 · View on GitHub

Tests Windows Build Stars Version License: PHP-3.01 Follow @iliaa

php_excel: 7-10× faster Excel I/O for PHP

Native C extension for reading and writing Excel files in PHP, powered by LibXL. 7-10× faster than PhpSpreadsheet with substantially lower memory pressure. Full XLS and XLSX support: rich text, conditional formatting, formulas, autofilters, form controls, embedded charts, and structured tables. PHP 8.1+ minimum. 2.0 ground-up modernization shipped April 2026.

🚀 Install

Via PIE (PHP Foundation's PECL successor):

pie install iliaal/php-excel \
  --with-libxl-incdir=/path/to/libxl/include_c \
  --with-libxl-libdir=/path/to/libxl/lib64

Or build from source:

phpize
./configure --with-excel \
  --with-libxl-incdir=/path/to/libxl/include_c \
  --with-libxl-libdir=/path/to/libxl/lib64
make
sudo make install

Then add extension=excel.so to your php.ini.

LibXL is a commercial library; download it from libxl.com and point the configure flags at its include_c and lib64 directories.

🛠️ Getting started

<?php
$book = new ExcelBook(null, null, true); // xlsx mode
$book->setLocale('UTF-8');

$sheet = $book->addSheet('Sheet1');

$data = [
    [1, 1500, 'John', 'Doe'],
    [2,  750, 'Jane', 'Doe'],
];

$row = 1;
foreach ($data as $item) {
    $sheet->writeRow($row++, $item);
}

// formula
$sheet->write($row, 1, '=SUM(B1:B3)');

// date with format
$dateFormat = new ExcelFormat($book);
$dateFormat->numberFormat(ExcelFormat::NUMFORMAT_DATE);
$sheet2 = $book->addSheet('Sheet2');
$sheet2->write(1, 0, (new DateTime('2024-08-02'))->getTimestamp(), $dateFormat, ExcelFormat::AS_DATE);

$book->save('output.xlsx');

📊 Performance

Write 100,000 rows × 20 columns vs PhpSpreadsheet 5.5.0 on PHP 8.4.19 NTS, Apple M3:

RowsCellsphp_excelPhpSpreadsheetSpeedup
1,00020K0.05s / 85 MB0.45s / 162 MB10×
10,000200K0.55s / 153 MB4.59s / 282 MB
50,0001M2.72s / 508 MB24.7s / 790 MB
100,0002M5.37s / 908 MB51.1s / 1,415 MB10×

Read performance is similar: 8-9× faster than PhpSpreadsheet, 3× faster than OpenSpout (with proportional memory tradeoff vs OpenSpout's flat 130 MB streaming model).

Why PhpSpreadsheet OOMs and php_excel doesn't

PHP's memory_get_peak_usage() reports about 2 MB for php_excel because LibXL allocates on the C heap, invisible to PHP's memory_limit. PhpSpreadsheet allocates in PHP's memory: it OOMs on 10,000 rows in a default 128 MB PHP-FPM pool. php_excel writes 100,000 rows in the same pool without raising the limit.

That's the practical difference. Bench numbers tell you it's faster; this tells you it's the difference between "report generates" and "report 500s in production."

📦 Classes

ClassDescription
ExcelBookWorkbook management: create, load, save, sheets, fonts, formats, pictures
ExcelSheetCell read/write, formatting, printing, protection, hyperlinks, data validation
ExcelFormatCell formatting: colors, borders, number formats, alignment, patterns
ExcelFontFont properties: name, size, bold, italic, underline, color
ExcelAutoFilterAutoFilter operations and sorting
ExcelFilterColumnFilter column criteria
ExcelRichStringMixed-font text in a single cell
ExcelFormControlForm controls: checkboxes, dropdowns, spinners, buttons
ExcelConditionalFormatConditional formatting style rules
ExcelConditionalFormattingConditional formatting ranges and rule application
ExcelCorePropertiesWorkbook metadata: title, author, dates, categories
ExcelTableStructured table support (xlsx)

2.0 added six new classes (ExcelRichString, ExcelFormControl, ExcelConditionalFormat, ExcelConditionalFormatting, ExcelCoreProperties, ExcelTable) plus full arginfo coverage: 399 typed parameters and 277 typed return values across the surface.

php.ini settings

Store LibXL credentials in php.ini instead of source code. The extension reads them automatically when you pass null to the constructor.

[excel]
excel.license_name="YOUR_LICENSE_NAME"
excel.license_key="YOUR_LICENSE_KEY"
excel.skip_empty=0

🔗 PHP Performance Toolkit

Companion native PHP extensions for high-throughput PHP workloads:

  • mdparser: native CommonMark + GFM markdown parser. 15-30× faster than pure-PHP libraries (Parsedown, cebe, michelf). Powered by cmark-gfm.
  • php_clickhouse: native ClickHouse client speaking the wire protocol directly. Picks up where SeasClick left off.
  • fastchart: native chart-rendering extension. 19 chart types behind one fluent OO API; composes with caller-owned \GdImage canvases.

📚 Read more

Full background, design rationale, and benchmark methodology in the launch post: php_excel 2.0: The C Extension for Excel That PHP Should Have Had All Along.

API reference lives in docs/; usage examples live in tests/.

License

PHP License 3.01. See LICENSE.

LibXL itself is commercial. See libxl.com for licensing.


Follow @iliaa on XBlog • If this sped up your stack, ⭐ star it!