I'm having a problem with PHP getenv() function, when I set a variable with putenv(KEY=VAL) I can fetch it directly with getenv(KEY) but it won't return as part of the array when I call getenv() without any key.
<?php
putenv("FOO=BAR");
var_dump(getenv('FOO'))
var_dump(getenv())
/app/releases/1/public/test.php:4:string 'BAR' (length=3)
/app/releases/1/public/test.php:5:
array (size=52)
'USER' => string 'apache' (length=6)
'HOME' => string '/usr/share/httpd' (length=16)
'HTTP_CONNECTION' => string 'keep-alive' (length=10)
'HTTP_ACCEPT_ENCODING' => string 'gzip, deflate, br' (length=17)
...
(more key => values but not 'FOO')
I see this note on PHP getenv() documentation site:
I'm not sure but if I'm using php-fpm which uses fpm-fcgi, then this behavior is expected ?
But what confuses me is that if I call the getenv('KEY') without setting the 2nd parameter (local_only) to true, I do get the value.
What I'm missing ? how can I resolve this ?
P.S.:
- I'm running PHP version
7.4.13with PHP-FPM + NGINX - I also tried to add
Etovariables_orderinphp.ini, but that didn't help - Same issue: getenv() doesn't show all variables, even if they are set
