Notinlist
Notinlist

Reputation: 16640

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?

Upvotes: 5

Views: 2087

Answers (2)

user229044
user229044

Reputation: 239230

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. 

Upvotes: 13

ghostdog74
ghostdog74

Reputation: 342273

how about the PHP_OS variable?

print PHP_OS;

Upvotes: 1

Related Questions