Oihana PHP

env

Table of Contents

Functions

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.

Functions

cpuCount()

Returns the number of CPUs available (if detectable).

cpuCount() : int
Tags
author

Marc Alcaraz

since
1.0.0
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
example
use function oihana\core\env\isCli;

if (isCli())
{
    echo "CLI mode\n";
}
author

Marc Alcaraz

since
1.0.0
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
example
use function oihana\core\env\isCliWithFile;

if (isCliWithFile())
{
    echo "CLI mode with script file\n";
}
else
{
    echo "Not a CLI script with a file\n";
}
author

Marc Alcaraz

since
1.0.0
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
author

Marc Alcaraz

since
1.0.0
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
author

Marc Alcaraz

since
1.0.0
Return values
bool

true if likely a cron job, false otherwise

isDebug()

Checks if PHP is running in debug mode.

isDebug() : bool
Tags
author

Marc Alcaraz

since
1.0.0
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
author

Marc Alcaraz

since
1.0.0
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
Tags
author

Marc Alcaraz

since
1.0.0
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
example
use function oihana\core\env\isInteractive;

if ( isInteractive() )
{
   echo "Interactive cli mode\n";
}
author

Marc Alcaraz

since
1.0.0
Return values
bool

true if interactive CLI, false otherwise

isLinux()

Indicates if the OS system is Linux.

isLinux() : bool
Tags
example
use function oihana\core\env\isLinux;

if ( isLinux() )
{
    echo "Linux environment\n";
}
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
bool

true if running on Linux, false otherwise

isMac()

Indicates if the OS system is Mac.

isMac() : bool
Tags
example
use function oihana\core\env\isMac;

if ( isMac() )
{
    echo "Mac environment\n";
}
author

Marc Alcaraz (ekameleon)

since
1.0.0
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
author

Marc Alcaraz

since
1.0.0
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
example
use function oihana\core\env\isWeb;

if (isWeb())
{
   echo "Web mode\n";
}
author

Marc Alcaraz

since
1.0.0
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
example
use function oihana\core\env\isWindows;

if ( isWindows() )
{
    echo "Windows environment\n";
}
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
bool

true if running on Windows, false otherwise

phpVersion()

Returns the current PHP version.

phpVersion() : string
Tags
example
use function oihana\core\env\phpVersion;

echo phpVersion() ;
author

Marc Alcaraz

since
1.0.0
Return values
string

The current PHP version.


        
On this page

Search results