Current Location: Home> Latest Articles> Use php_uname() to display the complete system information string

Use php_uname() to display the complete system information string

M66 2025-05-17

In PHP, the php_uname() function is a very practical function that returns the complete information of the current operating system. This function allows you to obtain the system name, version, and other details. It is usually used for debugging, diagnosing, and obtaining system-level information.

Introduction to php_uname() function

The php_uname() function returns a string about the operating system, and the content of the string depends on the operating system type. You can choose to call it without parameters, or specify parameters to get more specific information.

 string php_uname ([ string $mode = "a" ] )

Parameter description:

  • $mode : This parameter is optional. You can use the following mode to get different operating system information:

    • 'a' : By default, return system name, host name, operating system version and schema information.

    • 's' : Returns only the operating system name.

    • 'n' : Returns the host name of the computer.

    • 'r' : Returns the version of the operating system.

    • 'v' : Returns the version and patch level of the operating system.

    • 'm' : Returns the machine type (hardware architecture).

If the $mode parameter is not specified, all information will be returned by default.

Examples of usage

1. Obtain complete system information

By default, calling php_uname() will return detailed information including operating system name, host name, operating system version, etc.

 <?php
echo php_uname();
?>

Example output result:

 Linux servername 4.15.0-45-generic #48-Ubuntu SMP Thu Jan 17 15:10:52 UTC 2019 x86_64

2. Get the operating system name

If you only care about the name of the operating system, you can use the pattern 's' .

 <?php
echo php_uname('s');
?>

Example output result:

 Linux

3. Get the host name

To get the host name (computer name), you can use the mode 'n' .

 <?php
echo php_uname('n');
?>

Example output result:

 servername

4. Get the operating system version

If you need the version information of the operating system, you can use the mode 'r' .

 <?php
echo php_uname('r');
?>

Example output result:

 4.15.0-45-generic

5. Get the operating system version and patch level

If you need more detailed OS version information, including patch level, you can use the mode 'v' .

 <?php
echo php_uname('v');
?>

Example output result:

 #48-Ubuntu SMP Thu Jan 17 15:10:52 UTC 2019

6. Obtain the hardware architecture

If you need to query the system's hardware architecture type (such as x86_64), you can use the pattern 'm' .

 <?php
echo php_uname('m');
?>

Example output result:

 x86_64

summary

By using the php_uname() function, you can easily obtain various information about the operating system. You can choose different modes according to your needs to obtain different system details. This is very helpful for debugging, monitoring, and diagnosing problems.

URL Sample Code

If you use the URL in the code, you can replace the domain name part of the URL with m66.net . For example:

 http://m66.net/api/data