简体   繁体   中英

php-cli: What is the best way to detect the hosting OS?

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?

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. 

PHP_OS变量如何?

print PHP_OS;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM