Practical overview
When it fits
Use it when a PHP application needs a Transformers-like interface to pretrained ONNX models and its runtime environment can meet the platform-specific ONNX and PHP FFI requirements.
Who it is for
- PHP developers adding pretrained model tasks to an existing application.
- Teams using Hugging Face-hosted ONNX models from PHP.
Documented uses
- Add text generation, summarization or translation to a PHP project.
- Use a pipeline that groups a model with its task-specific preprocessing and postprocessing.
- Configure model downloads, caching, authentication or logging for an application.
Requirements & limits
- TransformersPHP uses ONNX Runtime and only works with ONNX models; PyTorch, TensorFlow or JAX models must be converted first.
- The ONNX dependency is platform-specific, so install the package in the target runtime environment.
- PHP FFI must be enabled for the library to interact with ONNX Runtime.
- Model weights are fetched on first use by default, which can delay the first pipeline run; pre-downloading intended models is recommended.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install TransformersPHP in the target PHP environment
Add the library through Composer and check the documented FFI requirement before using models.
Before you start
- A PHP environment; the README notes FFI is included in PHP 7.4 and later but may not be enabled.
- Access to Composer and the target execution environment.
Steps
Run
composer require codewithkyrian/transformerson the environment where the code will run.If FFI is not enabled, enable
extension = ffiand setffi.enable = truein php.ini.Restart the web server or PHP-FPM service after changing php.ini.
Expected outcome
The package is installed in the target environment with the documented FFI settings available for ONNX Runtime access.
Guide limitations
- The ONNX library is platform-specific, so installation should take place on the target platform, including inside the relevant Docker container.
- These steps cover installation and FFI configuration, not running a model.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 15 October 2026
- Original website title
- CodeWithKyrian/transformers-php · Official homepage title · retained in its source language

