PHP getenv() doesn't return all variables, even if they are set and can get directly

Viewed 660

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:

PHP getenv() Notes

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.:

0 Answers
Related