php_uname()
php_uname() — Returns information about the operating system PHP is running on.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
php_uname() returns a description of the operating system PHP is running on. This is the same string you see at the very top of the phpinfo() output. For the name of just the operating system, consider using the PHP_OS constant, but keep in mind this constant will contain the operating system PHP was built on.
Signature
php_uname(string $mode = "a"): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $mode | string | mode is a single character that defines what information is returned: 'a': This is the default. Returns the same information as the individual modes 's', 'n', 'r', 'v', 'm' separated by spaces. 's': Operating system name. eg. FreeBSD. 'n': Host name. eg. localhost.example.com. 'r': Release name. eg. 5.1.2-RELEASE. 'v': Version information. Varies a lot between operating systems. 'm': Machine type. eg. i386. |
Return value
Returns the description, as a string.
Example
A runnable snippet:
echo php_uname(); echo PHP_OS; /* Some possible outputs: Linux localhost 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686 Linux FreeBSD localhost 3.2-RELEASE #15: Mon Dec 17 08:46:02 GMT 2001 FreeBSD Windows NT XN1 5.1 build 2600 WINNT */ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { echo 'This is a server using Windows!'; } else { echo 'This is a server not using Windows!'; }
Changelog
| Version | Change |
|---|---|
| 8.4.0 | Throws a ValueError when an invalid mode is specified. |
See also
phpversion(), php_sapi_name(), phpinfo()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page php_uname() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.