env
Table of Contents
Functions
- completePath() : string
- Completes a PATH with the standard directories it lacks, added at its end.
- cpuCount() : int
- Returns the number of CPUs available (if detectable).
- isCli() : bool
- Checks if the PHP script is running in CLI mode (terminal, cron, Symfony Console…).
- isCliWithFile() : bool
- Checks if the PHP script is running in CLI mode **and** was launched with an actual file.
- isColorTerminal() : bool
- Checks if the CLI supports colors.
- isCron() : bool
- Checks if the script is likely running from a cron job.
- isDebug() : bool
- Checks if PHP is running in debug mode.
- isDocker() : bool
- Checks if PHP is running inside a Docker container.
- isExtensionLoaded() : bool
- Checks if a PHP extension is loaded.
- isInteractive() : bool
- Checks if the script is running in an interactive CLI (php -a or terminal input).
- isLinux() : bool
- Indicates if the OS system is Linux.
- isMac() : bool
- Indicates if the OS system is Mac.
- isOtherOS() : bool
- Checks if the operating system is **not Windows, Mac, or Linux**.
- isWeb() : bool
- Checks if the PHP script is running in a Web server context (not CLI).
- isWindows() : bool
- Indicates if the OS system is Windows.
- phpVersion() : string
- Returns the current PHP version.
- programLocations() : array<string, string|null>
- Finds where a PATH finds each program, as a shell would.
Functions
completePath()
Completes a PATH with the standard directories it lacks, added at its end.
completePath(string $path[, string $standard = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' ]) : string
A program started by cron, by a systemd unit or by any other way than a login shell does not
receive the PATH of a session. Cron, on many systems, gives /usr/bin:/bin and nothing more:
a program installed in /usr/local/bin is found by hand and missing at night, and what fails
is whatever needed it, often far from the cause. Some systems mend it — Ubuntu's cron reads
/etc/environment — and others do not, so a program that depends on its PATH should not trust
the one it is given.
Nothing is removed or moved: the standard directories come after those already there, so a program an administrator put earlier in the PATH still wins. Empty segments are dropped, and a directory is never listed twice by this function.
Parameters
- $path : string
-
The PATH as received; empty when there is none.
- $standard : string = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
-
The directories a PATH should hold, in their order, as a PATH. By default the one Debian and Ubuntu give a login session.
Tags
Return values
string —The PATH, completed.
cpuCount()
Returns the number of CPUs available (if detectable).
cpuCount() : int
Tags
Return values
int —The number of CPUs available (if detectable), null otherwise.
isCli()
Checks if the PHP script is running in CLI mode (terminal, cron, Symfony Console…).
isCli() : bool
Returns true if PHP is executed from the command line.
Tags
Return values
bool —true if the script is running in CLI, false otherwise
isCliWithFile()
Checks if the PHP script is running in CLI mode **and** was launched with an actual file.
isCliWithFile() : bool
Returns true if PHP is executed from the command line and $_SERVER['argv'][0] points to an existing file.
Tags
Return values
bool —true if running in CLI with a real script file, false otherwise
isColorTerminal()
Checks if the CLI supports colors.
isColorTerminal() : bool
Tags
Return values
bool —true if the CLI support colors, false otherwise
isCron()
Checks if the script is likely running from a cron job.
isCron() : bool
Tags
Return values
bool —true if likely a cron job, false otherwise
isDebug()
Checks if PHP is running in debug mode.
isDebug() : bool
Tags
Return values
bool —true if PHP is running in debug mode, false otherwise
isDocker()
Checks if PHP is running inside a Docker container.
isDocker() : bool
Tags
Return values
bool —true if running in Docker, false otherwise
isExtensionLoaded()
Checks if a PHP extension is loaded.
isExtensionLoaded(string $ext) : bool
Parameters
- $ext : string
-
The case-insensitive name of the extension (e.g.
'intl','bcmath').
Tags
Return values
bool —true if a PHP extension is loaded, false otherwise
isInteractive()
Checks if the script is running in an interactive CLI (php -a or terminal input).
isInteractive() : bool
Tags
Return values
bool —true if interactive CLI, false otherwise
isLinux()
Indicates if the OS system is Linux.
isLinux() : bool
Tags
Return values
bool —true if running on Linux, false otherwise
isMac()
Indicates if the OS system is Mac.
isMac() : bool
Tags
Return values
bool —true if running on Mac, false otherwise
isOtherOS()
Checks if the operating system is **not Windows, Mac, or Linux**.
isOtherOS() : bool
Tags
Return values
bool —true if the OS is neither Windows, Mac, nor Linux; false otherwise
isWeb()
Checks if the PHP script is running in a Web server context (not CLI).
isWeb() : bool
Returns true if PHP is executed via HTTP (e.g., Slim, Symfony HTTP, WordPress).
Tags
Return values
bool —true if the script is running in a web context, false otherwise
isWindows()
Indicates if the OS system is Windows.
isWindows() : bool
Tags
Return values
bool —true if running on Windows, false otherwise
phpVersion()
Returns the current PHP version.
phpVersion() : string
Tags
Return values
string —The current PHP version.
programLocations()
Finds where a PATH finds each program, as a shell would.
programLocations(array<string|int, string> $programs, string $path) : array<string, string|null>
For each name, the first file of that name in the directories of the PATH, in their order. A file that is there but not executable is not found: the shell would not run it.
Asked of a PATH other than the current one, it tells what a program started elsewhere — by cron, by a service — will find, which is not what a session finds. Paired with completePath(), it says whether completing a PATH is enough.
Parameters
- $programs : array<string|int, string>
-
The program names, as a command line spells them.
- $path : string
-
The PATH to look in.
Tags
Return values
array<string, string|null> —Each program, in the order given, with the file the PATH finds for it, or null.