majorsilence/reporting
Render RDL reports to PDF, Excel, CSV, and more from PHP — via subprocess, an AOT binary, or in-process PHP FFI. PHP 8.1+. No Composer runtime dependencies.
Installation
Install via Composer (PHP 8.1+ required):
composer require majorsilence/reporting
Or clone the repository and require the autoloader manually:
require_once __DIR__ . '/vendor/autoload.php';
No runtime Composer dependencies. The native FFI mode additionally requires ext-ffi and ffi.enable=true in php.ini.
Integration modes
| Class | Mechanism | Requirement |
|---|---|---|
| Report | Spawns dotnet RdlCmd.dll via proc_open. | .NET runtime on the server. |
| ReportAot | Spawns a self-contained AOT-compiled RdlCmd binary via proc_open. | AOT binary deployed alongside the app. No .NET runtime needed. |
| ReportNative | Loads librdlnative.so in-process via PHP FFI. Use RdlLibrary::load() to obtain the FFI instance. | ext-ffi, ffi.enable=true, and the native library on LD_LIBRARY_PATH. |
Report — subprocess (dotnet)
use MajorsilenceReporting\Report; $rpt = new Report( '/path/to/report.rdl', '/path/to/RdlCmd.dll' ); $rpt->set_connection_string('Data Source=/path/to/data.db'); $rpt->set_parameter('StartDate', '2026-01-01'); // Save to disk $rpt->export('pdf', '/tmp/output.pdf'); // Or stream to the browser $data = $rpt->export_to_memory('pdf'); header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="report.pdf"'); echo $data;
ReportAot — AOT binary
Same API as Report but points at a self-contained binary. No .NET runtime required. Also unlocks additional export formats (xlsx_table, tifb, mht).
use MajorsilenceReporting\ReportAot; $rpt = new ReportAot( '/path/to/report.rdl', '/path/to/RdlCmd' // self-contained binary ); $rpt->set_connection_string('Data Source=/path/to/data.db'); $data = $rpt->export_to_memory('xlsx_table'); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); echo $data;
ReportNative — PHP FFI
Load librdlnative.so directly into the PHP process via FFI. No child process is spawned. Requires ext-ffi and ffi.enable=true.
use MajorsilenceReporting\ReportNative; use MajorsilenceReporting\RdlLibrary; // Load the native library once. Sets RDLNATIVE_LIB_DIR automatically. $lib = RdlLibrary::load('/path/to/librdlnative.so'); $rpt = new ReportNative($lib, '/path/to/report.rdl'); $rpt->set_connection_string('Data Source=/path/to/data.db'); $data = $rpt->export_to_memory('pdf'); header('Content-Type: application/pdf'); echo $data;
extension=ffi and ffi.enable=true in php.ini. The native library directory must be on LD_LIBRARY_PATH before PHP starts — RdlLibrary::load() sets RDLNATIVE_LIB_DIR but cannot retroactively update LD_LIBRARY_PATH for the current process.
Core API
All three classes share the same interface (PSR-4 namespace MajorsilenceReporting\):
| Method | Description |
|---|---|
| set_connection_string(string $cs) | Set the database connection string. Call before export. |
| set_parameter(string $name, string $value) | Set a named report parameter. Call as many times as needed. |
| export(string $type, string $path) | Render the report and write the output to $path on disk. |
| export_to_memory(string $type): string | Render and return the output as a binary string (for PDF, TIFF, RTF, XLSX) or UTF-8 string (for CSV, XML, HTML). |
In-memory datasets
ReportNative supports supplying data entirely in memory via add_data() — no database connection needed. Pass a dataset name and an array of associative arrays where every value is a string.
$rpt->add_data('SalesData', [ ['Product' => 'PDF Library Pro', 'Revenue' => '1200.00', 'Units' => '3'], ['Product' => 'Report Designer', 'Revenue' => '250.00', 'Units' => '1'], ['Product' => 'Support (12 mo.)', 'Revenue' => '500.00', 'Units' => '1'], ]); $data = $rpt->export_to_memory('pdf');
add_data() is only available on ReportNative, not on Report or ReportAot. The dataset name must match a dataset defined in the .rdl file. All field values must be strings.
Export formats
| Format string | Output | Available in |
|---|---|---|
pdf | All modes | |
csv | CSV text | All modes |
xlsx | Excel workbook | All modes |
xml | XML data | All modes |
rtf | Rich Text Format | All modes |
tif | TIFF image (colour) | All modes |
html | HTML | All modes |
xlsx_table | Excel (table style) | ReportAot + ReportNative only |
tifb | TIFF image (black & white) | ReportAot + ReportNative only |
mht | MHTML web archive | ReportAot + ReportNative only |