Possible Values For: PHP_OS
Asked Answered
S

3

60

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!

Seethe answered 10/4, 2009 at 20:51 Comment(0)
S
25

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)
Sahara answered 10/4, 2009 at 21:14 Comment(2)
This is wrong. On Windows 7 php_uname('s') == "Windows NT" and PHP_OS == "WINNT", neiter is mentioned on that Wikipedia page.Napoli
@Napoli 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.Sahara
A
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?

Abscise answered 10/4, 2009 at 21:15 Comment(4)
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.Seethe
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.Abscise
@NickPresta, example (and real world) scenario: locale codes for setlocale() differ greatly in Windows (see 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.Boarder
+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.Wingspan
A
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:
Awoke answered 21/6, 2013 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.