klitsche/ffigen
CLI tool to generate and update low-level PHP FFI bindings from C headers. Produces constants.php and Methods.php (static method wrappers with phpdoc). Configurable via .ffigen.yml and optional custom parser hooks for preprocessing.
ext-mysql vs. modern libmysqlclient).Adopt if:
Look elsewhere if:
ext-curl, ext-pdo_mysql, ext-sodium) or existing SDKs (e.g., AWS SDK for PHP).FFI extension directly for ad-hoc use cases.dox.php or php-cpp for stricter typing).*"This tool eliminates the manual, error-prone process of writing and maintaining PHP bindings for C libraries—saving weeks of development time per project. For example, integrating a custom database driver or hardware security module (HSM) into Laravel would typically require a senior engineer to hand-write bindings and debug them as the C library evolves. FFIGen automates this by generating bindings from header files, ensuring they stay sync’d with upstream changes.
Key Benefits:
Example Use Case: If we’re building a Laravel-based payment processor, we could use FFIGen to wrap a legacy C-based fraud detection library—avoiding a full rewrite while modernizing the stack. The tool’s YAML-driven configuration makes it easy to adapt to new libraries as needed."*
*"FFIGen lets us treat C libraries like first-class citizens in Laravel:
libssl patch) via CI/CD.#define macros, map C types to Laravel collections) via a Parser class.composer install or PR checks.How It Fits Laravel:
App\Services\HSMService).HSM::encrypt()).php artisan hsm:rotate-keys).Trade-offs:
composer.json to avoid breaking changes.try-catch).Proposal:
libuuid for demo purposes).Key Metric: ‘Time spent maintaining FFI bindings’ (target: reduce by 70% for new integrations)."*
Example Pitch for Stakeholders: "Imagine we’re adding HSM support to Laravel Cashier for PCI compliance. Instead of spending 2 months writing and debugging PHP bindings for the HSM’s C SDK, FFIGen could generate them in 2 hours—with zero maintenance overhead as the SDK evolves. This isn’t just about saving time; it’s about enabling features we’d otherwise avoid due to integration complexity. Let’s pilot this for our next high-priority C library integration."
How can I help you explore Laravel packages today?