I have a script which I want to run on windows under Cygwin and on Linux. I have to make distinction between the two running environment for some purposes. What is the best way to do it?
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.
As of PHP 7.2. 0 we have a new Predefined Constant to get the operating system family i.e. PHP_OS_FAMILY. It returns a string Either of 'Windows', 'BSD', 'OSX', 'Solaris', 'Linux' or 'Unknown'.
There is a pre-defined constant PHP_OS which will help, but only displays the OS that PHP was built on, not the OS it is running on.
php_uname
is what you want to discover information about the current server running your code:
php_uname() returns a description of the operating system PHP is running on.
Specifically,
php_uname('s'); // Operating system name. eg. FreeBSD.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With