← SDKs
PHP SDK

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

ClassMechanismRequirement
ReportSpawns dotnet RdlCmd.dll via proc_open..NET runtime on the server.
ReportAotSpawns a self-contained AOT-compiled RdlCmd binary via proc_open.AOT binary deployed alongside the app. No .NET runtime needed.
ReportNativeLoads 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;
PHP FFI requires 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\):

MethodDescription
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): stringRender 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 stringOutputAvailable in
pdfPDFAll modes
csvCSV textAll modes
xlsxExcel workbookAll modes
xmlXML dataAll modes
rtfRich Text FormatAll modes
tifTIFF image (colour)All modes
htmlHTMLAll modes
xlsx_tableExcel (table style)ReportAot + ReportNative only
tifbTIFF image (black & white)ReportAot + ReportNative only
mhtMHTML web archiveReportAot + ReportNative only