Documentation
¶
Overview ¶
Package phpdiscover finds all PHP binaries installed on the current machine.
Every candidate is collected, verified and deduplicated. Candidates come from four places:
- every directory in $PATH (php, php8, php8.2, php8.2.3, php-cli, ...)
- the "known locations" used by hosting providers, turned into glob patterns so that every installed version matches
- well-known installation directories (Homebrew, Nix, phpbrew, phpenv, asdf-vm, MAMP, XAMPP, MacPorts, Ondrej PPA, Remi, Herd, ...)
- extra directories supplied by the caller
Every candidate is verified by running `php --version` (with a timeout), and results are deduplicated by the resolved (real) path. Sibling binaries of the same installation (php-fpm, php-cgi, php-config, phpize, phpdbg) are attached when they exist.
The package has no external dependencies.
Index ¶
Constants ¶
const ( SourcePath = "PATH" SourceUsr = "/usr" SourceKnownLocation = "known-location" SourceHomebrew = "homebrew" SourceNix = "nix" SourceAsdf = "asdf-vm" SourcePhpbrew = "phpbrew" SourcePhpenv = "phpenv" SourceMAMP = "MAMP" SourceXAMPP = "XAMPP" SourceMacPorts = "MacPorts" SourceOndrej = "ondrej-ppa" SourceRemi = "remi" SourceLiip = "Liip" SourceHerd = "Herd" SourceHerdLite = "herd-lite" SourceWAMP = "WAMP" SourceCygwin = "Cygwin" SourceChocolatey = "chocolatey" SourceExtra = "extra" )
Source names, describing where a PHP binary was found.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*config)
Option customizes a discovery run.
func WithConcurrency ¶
WithConcurrency sets how many candidate binaries are probed in parallel. Defaults to 4.
func WithExtraDirs ¶
WithExtraDirs adds directories that are scanned for php-like executables.
func WithLogger ¶
WithLogger installs a logger that receives progress messages.
func WithSources ¶
WithSources restricts discovery to exactly the given sources (see Source* constants). When set, all other sources are ignored. It can be combined with WithoutSource to exclude individual sources from the allowlist.
func WithTimeout ¶
WithTimeout sets the maximum time a single `php --version` probe (or the brew/nix/asdf lookups) may take. Defaults to 5 seconds. Non-positive values keep the default timeout.
func WithoutSource ¶
WithoutSource disables a discovery source (see Source* constants). It can be called multiple times.
type PHP ¶
type PHP struct {
// Path is the absolute path to the PHP binary with all symlinks resolved.
Path string
// OriginalPath is the path as it was discovered (may be a symlink).
OriginalPath string
// Version is the parsed version reported by `php --version`.
Version Version
// Source describes where this binary was found (see Source* constants).
Source string
// IsSystem is true for the first PHP binary found in $PATH.
IsSystem bool
// FPMPath, CGIPath, PHPConfigPath, PHPizePath and PHPdbgPath are sibling
// binaries of the same PHP installation, when present.
FPMPath string
CGIPath string
PHPConfigPath string
PHPizePath string
PHPdbgPath string
}
PHP describes a single locally available PHP binary.
func Default ¶
Default returns the system PHP (the first one found in $PATH) if any, otherwise the newest available binary, or nil if none was found.
func Discover ¶
Discover returns all locally available PHP binaries, sorted by version.
Discovery is best-effort: directories that cannot be read, binaries that fail to run or that do not respond with a PHP version are silently skipped. The context is used to bound the runtime of the probes; a canceled context stops new probes from being started but keeps the results found so far.
func FindVersion ¶
FindVersion returns the newest PHP binary matching a version prefix such as "8", "8.2" or "8.2.3", or nil if none matches.
type Version ¶
type Version struct {
Major int
Minor int
Patch int
// Extra contains an optional suffix reported by PHP,
// e.g. "-1ubuntu2.14" for Debian packaged PHP or "RC4" for release candidates.
Extra string
}
Version is a parsed PHP version like 8.2.3.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
phpdiscover
command
Command phpdiscover lists all PHP binaries found on the current machine.
|
Command phpdiscover lists all PHP binaries found on the current machine. |