PHP-ML in production: an honest review
Tried using php-ai/php-ml for a text classification task in a Symfony app. Wanted to avoid calling an external API for latency reasons.
Results were mixed. Sharing what worked and what did not.
PHP-ML is fine for simple models trained on small datasets. Anything requiring matrix operations on large data will be slow. The library is pure PHP, no BLAS bindings. Python with scikit-learn will be 20x faster for training.
Used it for a spam classifier on forum posts: Naive Bayes, about 5k training examples. Training takes 2 seconds, inference is instant, accuracy is 87%. For that use case it works well enough and eliminates the API dependency.
If you need better accuracy and can tolerate a Python dependency, ONNX Runtime has a PHP FFI wrapper. You train in Python, export to ONNX, run inference from PHP at near-native speed. That is what we do.
For production I would evaluate whether a dedicated microservice (Python FastAPI wrapping your model) is worth the operational complexity vs using a hosted API. The latency of a local HTTP call to a Python service is still much lower than OpenAI API.
What classification problem were you solving? Curious whether PHP-ML Naive Bayes or SVM is more practical for text.
Tried both: SVM accuracy was slightly higher (89%) but training time was 10x longer. For daily retraining Naive Bayes is the practical choice. SVM makes sense if you train once and cache the model.