Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP_OS - does it contain OS it was built on or runs on?

Tags:

php

I searched for quite a while now, but i could not find a definite answer to the question wether the constant PHP_OS contains the OS php was built on or runs on.

The php documentation of php_uname (http://php.net/manual/de/function.php-uname.php) states: "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. "

However, on the very same page there is a comment from 2006 stating: "Contrary to the last note, PHP_OS does display the OS PHP runs on currently, [...] This has nothing to do with the system PHP was built on."

I could not find any definite answer anywhere on the web regarding this question (topis about php_uname and PHP_OS mostly only cover os detection and similar topics). What's right now - the documentation or the comment?

The pear-core package uses PHP_OS to determine wether it's running on Unix-like systems or on windows, so is it safe to assume the documentation is indeed wrong?

like image 720
StandByUkraine Avatar asked Jan 18 '26 21:01

StandByUkraine


2 Answers

I had a look at the source code. The configure script does this:

PHP_OS=`uname | xargs`
AC_DEFINE_UNQUOTED(PHP_OS,"$PHP_OS",[uname output])

and then main.c does this:

char *php_os;
php_os=PHP_OS;
REGISTER_MAIN_STRINGL_CONSTANT("PHP_OS", php_os, strlen(php_os), CONST_PERSISTENT | CONST_CS);

which means that PHP_OS in PHP is what was in php_os in the C code, which is what was #defined by the header file constructed by the configure script, which is determined by running uname at configuration time.

So, it's the system you were built on, not the system you were running on.

There's some special-cased code for Windows: main.c sets php_os to "WINNT" if WIN32 is defined. But, again, this is at build time, not at run time, even if you manage to compile on Unix and run on Windows or vice versa.

like image 88
Gareth McCaughan Avatar answered Jan 21 '26 10:01

Gareth McCaughan


PHP_OS (the PHP constant) is a constant defined when the PHP module starts up. Its value comes from either the PHP_WIN32 or PHP_OS C constants (following the trail finally leads to this, but that's not necessary to answer the question).

So what it describes is the system PHP was built on.

like image 32
Jon Avatar answered Jan 21 '26 10:01

Jon