kachkaev/php-r
PHP-R is a PHP wrapper for running R code from PHP applications. It lets you evaluate R expressions, pass data between PHP and R, and retrieve results, making statistical computing and R-based analysis accessible from PHP projects.
Architecture fit
php-r is a single-purpose, dependency-light library that implements R-style vectors as PHP values: element-wise arithmetic, recycling, NA handling, and statistical helpers (mean, median, sd). Architecturally it is a leaf utility, not a framework or service, so it does not impose structure on the host application. That makes it a plausible fit for narrow use cases—reporting helpers, internal dashboards, lightweight ETL, or exploratory analysis embedded in a PHP codebase—where a team wants R-like semantics without introducing a second runtime. It is a poor fit for core domain logic, high-volume data paths, or anything requiring sustained vendor support.
Integration feasibility
composer require).Technical risk
NA propagation are powerful but surprising to PHP developers; silent length-mismatch recycling is a classic source of subtle bugs.Key questions
composer.json declare, and does the suite pass on our target runtime (e.g., PHP 8.1+)?NA, and edge cases (empty vectors, zero-length recycling)?Stack fit Any Composer-based PHP application (Laravel, Symfony, plain PSR-4) can consume it, but it belongs in a service/helper layer behind an internal interface—not sprinkled through controllers or models. Laravel teams should wrap it in a small service class and bind it via the container so it is mockable and replaceable. Treat it as an optional analytics utility, not a platform dependency.
Migration path
VectorMath (or similar) interface that expresses only the operations actually needed (sum, mean, element-wise add, NA-aware aggregation).php-r behind an adapter; the rest of the codebase never imports the package directly.Compatibility
E_ALL.Sequencing
Maintenance Archived means no upstream maintenance. The realistic operating model is either (a) freeze-and-accept, with a documented exception, or (b) internal fork with an assigned owner and a lightweight CI matrix across supported PHP versions. Budget recurring effort for PHP upgrade compatibility reviews—this is the dominant long-term cost.
Support There is no vendor or community support channel of consequence. Internal documentation, examples, and tests become the support surface. Developers must be able to read the source to diagnose behavior, so keep the vendored code accessible and annotated.
Scaling
The library is in-memory and single-process; scaling is bounded by memory_limit and request/worker time. It is appropriate for small-to-moderate vectors (thousands to low hundreds of thousands of elements, workload-dependent) and inappropriate for large datasets, streaming, or parallel computation. If data volume grows, the adapter boundary allows migration to a queue-based job, a columnar store, or an analytical service without rewriting callers.
Failure modes
NA/type coercion surprises, especially mixing ints, floats, and nulls.Ramp-up
Low for developers with R or NumPy exposure; moderate for PHP-only developers who must internalize recycling rules and NA propagation. The API surface is small, so a short internal guide plus the adapter tests is usually sufficient. The bigger ramp-up cost is organizational: getting the team comfortable with owning an abandoned dependency.
TPM recommendation
Leverage php-r only as an isolated, adapter-wrapped utility for low-risk analytical features, and only after a compatibility spike on the target PHP version. Do not adopt it for core or customer-critical paths without an explicit decision to fork and own it. If policy forbids unmaintained dependencies, use this assessment to justify either a one-time fork with CI or replacement by a native-PHP reference implementation behind the same interface.
How can I help you explore Laravel packages today?