Skip to content

Add PHP binary path override - #41

Merged
fabpot merged 2 commits into
mainfrom
php-binary-override
Aug 3, 2026
Merged

Add PHP binary path override#41
fabpot merged 2 commits into
mainfrom
php-binary-override

Conversation

@fabpot

@fabpot fabpot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@upsun-dispatch

upsun-dispatch Bot commented Aug 3, 2026

Copy link
Copy Markdown

📋 PR Summary

This PR adds a SYMFONY_CLI_PHP_BINARY_PATH environment variable that lets users force a specific absolute PHP CLI binary path, bypassing automatic version selection (resolving issue #599 where multiple installations share the same version). It refactors PHP discovery in discovery.go into a reusable inspectPHPBinary helper plus a new discoverPHPPath entry point, injects the --version runner via a phpVersionOutput field for testability, and adds a sortVersions helper that rebuilds the seen index after sorting.

Changes
Layer / File(s) Summary
override entry point
store.go Adds the PHPBinaryPathEnvVar constant and a highest-priority branch in BestVersionForDir that discovers and selects the overridden binary; extracts sortVersions which now rebuilds the seen map after each sort.
discovery refactor
discovery.go Splits binary inspection into inspectPHPBinary, adds discoverPHPPath for absolute/standalone binaries, and extracts runPHPVersion behind the injectable phpVersionOutput field.
tests
store_test.go Adds tests covering the override happy path, symlink resolution, standalone binaries, and rejection of relative / non-PHP paths.
docs
README.md Documents the new SYMFONY_CLI_PHP_BINARY_PATH override.

Comment thread store.go
return nil, source, "", errors.Wrapf(err, "invalid %s", PHPBinaryPathEnvVar)
}
selected = s.versions[s.addVersion(selected)]
s.sortVersions()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning — Concurrent override calls can fatally panic, and every call redundantly re-execs and re-sorts.

The SYMFONY_CLI_PHP_BINARY_PATH branch turns BestVersionForDir — otherwise a read-only query — into a writer: s.addVersion(selected) appends to s.versions and s.sortVersions() rebuilds the s.seen map (re-evalSymlinks-ing every entry) on every call, and discoverPHPPath re-execs php --version each time. Two side effects follow: every invocation with the override set repeats the exec and full re-sort, and if two goroutines call BestVersionForDir with the override active the unsynchronized writes to s.seen can trigger Go's fatal "concurrent map writes" panic (the non-override paths never mutate this map).

Comment thread discovery.go
binName = binName[:len(binName)-len(extension)]
}
discoverCompanions = strings.Contains(binName, "php")
} else if filepath.Base(dir) == "bin" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Info — Override of non-standard PHP layouts drops FPM/CGI server support.

On non-Windows, companion (FPM/CGI/config) discovery is enabled only when the resolved binary's parent directory is literally named bin (filepath.Base(dir) == "bin"). An override pointing at a custom-built PHP whose CLI binary is not under a bin/ directory (e.g. /opt/php8.4/php) is reported as a CLI-only installation with empty FPMPath/CGIPath even when a php-fpm/php-cgi sits alongside it, so the override silently loses FPM/CGI capability for such layouts.

@fabpot
fabpot merged commit ee0f7f1 into main Aug 3, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Can't select specific PHP binary when multiple installations share the same version

1 participant