Skip to content

feat(php): compile extensions from source when unavailable in static builds #2

Description

@eddmann

Summary

When a requested extension is not available in the pre-built static PHP binaries (common or bulk tiers), phpx should fall back to compiling the extension from source instead of failing.

Current Behavior

Extensions are specified in the // phpx metadata block:

// phpx
// php = ">=8.2"
// extensions = ["redis", "imagick"]

phpx checks if extensions are available in the "common" or "bulk" static PHP builds from static-php.dev. If an extension isn't available in either tier, resolution fails with:

extension 'foo' not available in static PHP builds

See internal/index/index.go:433 in RequiredTier().

Proposed Behavior

Instead of failing, phpx should:

  1. Select the best available static PHP build (common/bulk) for extensions that are available
  2. For extensions not in static builds, download source from PECL and compile them
  3. Cache compiled extensions in ~/.phpx/extensions/<php-version>/<ext-name>/
  4. Load compiled extensions via -d extension=/path/to/ext.so

Implementation Considerations

  • Source retrieval: Download from PECL (https://pecl.php.net/get/<ext>-<version>.tgz)
  • Compilation: Run phpize, ./configure, make against the static PHP headers
  • Caching: Store compiled .so files keyed by PHP version and extension version
  • Dependencies: Some extensions need system libraries (e.g., ImageMagick for imagick)
  • Build tools: Requires gcc, make, autoconf - should detect and report if missing
  • Version selection: Default to latest stable PECL version, allow pinning via extensions = ["redis:5.3.7"]

Example

// phpx
// php = ">=8.3"
// extensions = ["redis", "some-obscure-ext"]
  • redis → available in bulk tier, use static build
  • some-obscure-ext → not in static builds, compile from PECL

Additional Context

  • This extends the existing extension system without changing the user-facing syntax
  • Compiled extensions would be cached alongside PHP binaries in ~/.phpx/
  • Should gracefully handle compilation failures with clear error messages

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions