Php-cli: What is the best way to detect an operating system?

I have a script that I want to run on Windows under Cygwin and Linux. I have to make a distinction between two working environments for some purposes. What is the best way to do this?

+4
source share
2 answers

There is a predefined constant PHP_OS that will help, but only displays the OS on which PHP was built in, and not the OS on which it runs.

php_uname is what you want to know about the current server your code is running on:

php_uname () returns a description of the operating system that PHP is running on.

In particular,

 php_uname('s'); // Operating system name. eg. FreeBSD. 
+10
source

what about the PHP_OS variable?

print PHP_OS;

+1
source

Source: https://habr.com/ru/post/1300067/


All Articles