Matthew Herbst
Matthew Herbst

Reputation: 32023

PHP: difference between getenv() and apache_getenv()

I'm using an Apache 2 server and hosting a web app there. I'm setting some environment variables in my vhost by using the Apache SetEnv VARIABLE value command.

When looking to retrieve the value in PHP, I've some across two methods. getenv() and apache_getenv().

Is there any real difference? Is there a reason to prefer one over the other? Not sure what the point of have the apache_getenv() method is if getenv() works the same and allows your code to be server agnostic.

Upvotes: 5

Views: 1997

Answers (1)

bishop
bishop

Reputation: 39444

getenv calls apache_getenv if you're running the Apache SAPI, otherwise it asks the system. So, no, there is no real functional difference. Stick with getenv.

Upvotes: 10

Related Questions