phit

Guides

Deploying to servers

The deployed PHP process needs only phit.so and its system libraries. Rust, Clang, PIE, R and Python are build or development tools and are not needed at runtime. Installation covers PIE and the prebuilt binaries; this page covers PHP-FPM, containers and manual builds.

Names

  • Composer and PIE package: phpstats/phit.
  • Registered extension: phit. Use it with extension_loaded('phit'), phpversion('phit'), get_extension_funcs('phit') and Composer’s ext-phit.
  • Installed module: phit.so. A direct Cargo build produces libphit.so on Linux and libphit.dylib on macOS; they are the same extension.
  • Functions are in the Phit namespace, such as Phit\fit_lm.

Supported targets

The extension supports PHP 8.3, 8.4 and 8.5, non-thread-safe, on Linux and macOS. Windows and ZTS builds are not supported. The prebuilt binaries, which pie install downloads on Linux, are built on Debian Bookworm for x86_64 and arm64 and need glibc 2.35 or later. Alpine (musl) and older glibc releases need a source build with PIE or by hand. CI tests Linux x86_64 and arm64 at all three PHP versions, and macOS on Apple silicon.

PHP-FPM

PHP loads the extension when a process starts. After installing or replacing phit.so:

  1. Enable it in the configuration PHP-FPM reads. php --ini shows the CLI’s files, which can differ from FPM’s.
  2. Restart the PHP-FPM service so every worker loads the new module.
  3. Check the web runtime, not only the CLI, for example with extension_loaded('phit') and phpversion('phit') in a request.

Each call converts PHP arrays into Rust vectors, fits the model and returns an array within the request. No background process, subprocess or network service is involved.

A PHP-FPM container image

docker/Dockerfile builds a PHP-FPM image with the extension installed. From the repository root:

docker build --target checks -f docker/Dockerfile -t phit:checks .
docker build -f docker/Dockerfile -t phit:local .
./scripts/check-container phit:local phit:checks

The build installs the extension through PIE 1.5.0 and runs the Rust and PHP checks. The isolated FPM check sends a real FastCGI request. The production-image check then exercises both CLI and FPM using the shipped PHP configuration and verifies identical OLS coefficients and a Poisson log-exposure fit.

The final image contains the PHP runtime and installed extension. Rust, Clang, PIE, Python, repository sources, and test utilities remain in the build stages. The image retains the official PHP entrypoint and foreground PHP-FPM command. Use it as an application base:

FROM phit:local
COPY app/ /var/www/html/

Connect your normal web server to FPM. FPM speaks FastCGI, not HTTP; no public FPM listener is needed for the tests. The verification script removes only its own temporary container and never edits a production PHP/FPM configuration.

Build pins and reproducibility

The Dockerfile pins PHP and Rust base images by OCI digest. The workflow records separate PHP 8.3/8.4/8.5 image digests. Build and runtime stages share exactly the same PHP image. Cargo.lock pins Rust dependencies; the downloaded PIE PHAR has a pinned SHA-256. Update those pins deliberately and rerun the gate.

Debian APT packages are resolved at build time. These pins establish a repeatable base and dependency selection, not a promise that every future rebuild has the same bytes. Binary manifests record the compiler, PHP API, architecture, libc, linked libraries, extension hash and Cargo.lock hash.

Manual build without PIE

From a checkout of the repository or the release’s source archive, the standard phpize build works without PIE. pie/config.m4 and pie/Makefile.frag run the locked Cargo build:

cd pie
/path/to/phpize
./configure --with-php-config=/path/to/php-config
make -j4
# Stage without modifying the installed PHP runtime:
make install INSTALL_ROOT=/absolute/path/to/staging
# Or install after reviewing the build:
# sudo make install

Build as an unprivileged user before installing. The install goal requires the already built module and does not rerun Cargo under sudo. INSTALL_ROOT stages under the configured extension directory. On macOS, use the matching LLVM/header setup in the development guide.

Add extension=phit.so to the relevant PHP INI configuration after a manual install. Inspect php --ini for CLI; check the FPM configuration separately. Verify the native functions through both. Rebuild for another PHP ABI, architecture, thread-safety/debug configuration, or platform.

From phpstats/phit@76b22f0.