59

Is there a place to find a list of the possible values for the PHP predefined constant PHP_OS ? I'd like to use this value for a system requirements check, but need to know how different operating systems are named in this variable.

Through some searching, so far I've compiled the following list:

  • CYGWIN_NT-5.1
  • Darwin
  • FreeBSD
  • HP-UX
  • IRIX64
  • Linux
  • NetBSD
  • OpenBSD
  • SunOS
  • Unix
  • WIN32
  • WINNT
  • Windows

If anyone has a more complete list, or knows of any additional values I'd love to hear them!

Wilco
  • 32,754
  • 49
  • 128
  • 160

3 Answers3

24

PHP passes through the uname, except on Windows (WINNT) and Netware (Netware). See Wikipedia for a non-exhaustive list of values not mentioned in your question:

  • CYGWIN_NT-5.1
  • IRIX64
  • SunOS
  • HP-UX
  • OpenBSD (not in Wikipedia)
phihag
  • 278,196
  • 72
  • 453
  • 469
  • 1
    This is wrong. On Windows 7 `php_uname('s') == "Windows NT"` and `PHP_OS == "WINNT"`, neiter is mentioned on that Wikipedia page. – AndreKR May 27 '16 at 03:33
  • @AndreKR Windows is one exception. Note that I'm answering the question by @Wilco, which asked for *additional* values, and already mentioned `WINNT`. Nevertheless, I've updated the answer and linked to the source code which proves that `uname` is being used. – phihag May 27 '16 at 07:13
4

I think a better solution to do a 'requirement check' would be to actually use things that you need to know work properly and see what happens.

For example, there are constants for directory separators, functions like realpath(), etc to deal with directories on different operating systems.

What, specifically, are you trying to do?

Nick Presta
  • 28,134
  • 6
  • 57
  • 76
  • That certainly makes sense, but I'm trying to run a check on operating systems my script has been tested on. In that case, I only really need a subset of the possible values, but a full list could prove useful. – Wilco Apr 10 '09 at 21:17
  • It is your choice. I just want to point out that in the future, other values could crop up (WIN64 perhaps), so you will need to check for those periodically. – Nick Presta Apr 10 '09 at 21:41
  • 1
    @NickPresta, example (and real world) scenario: locale codes for `setlocale()` differ greatly in Windows (see http://msdn.microsoft.com/en-us/library/39cwe7zf%28vs.71%29.aspx). You need to know your OS in order to call `setlocale()` properly. Even then, as you imply, this feels like a very awkward solution. – Halil Özgür Jun 08 '12 at 00:17
  • 1
    +1, but I need OS checking because the PCRE stack size varies greatly from Windows to Linux (256KB vs. 8MB), so I need to do an `ini_set` on Windows to limit recursion (to avoid a segfault). Ugly, but yeah... it's PHP we're talking about. – Camilo Martin Nov 01 '13 at 00:13
0

it seems like the php_uname("s") for non-Unix OSes would be a good start, since it looks to me like uname("s") and php_uname("s") are the same on Unix systems and posix sub systems, such as Cygwin, Mingw, UWin, EMX+GCC, and MKS. Below is a list of OSes that are not Posix-compliant out of the box and that run PHP.

OS

  • OS/2 Warp
  • eComStation
  • RISC OS
  • Windows XP 64-bit

Keep in mind, this is not at all for Browser detection, but root path detecting, directory separators that may or may not be \ and /, EOL, and a few other things.

Examples of root paths

  • Unix\linux\Mac OS X: /
  • OS/2: C:\
  • Amiga: dh0:
Scz
  • 650
  • 7
  • 13
marz201
  • 1
  • 1