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:
- Select the best available static PHP build (common/bulk) for extensions that are available
- For extensions not in static builds, download source from PECL and compile them
- Cache compiled extensions in
~/.phpx/extensions/<php-version>/<ext-name>/
- 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
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
// phpxmetadata block: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:
See
internal/index/index.go:433inRequiredTier().Proposed Behavior
Instead of failing, phpx should:
~/.phpx/extensions/<php-version>/<ext-name>/-d extension=/path/to/ext.soImplementation Considerations
https://pecl.php.net/get/<ext>-<version>.tgz)phpize,./configure,makeagainst the static PHP headers.sofiles keyed by PHP version and extension versionextensions = ["redis:5.3.7"]Example
redis→ available in bulk tier, use static buildsome-obscure-ext→ not in static builds, compile from PECLAdditional Context
~/.phpx/