20

Title says it. I want to use this with proc_open, to append some variables to the current environment.

$current_env = get_all_env_vars_magically();
$env = array_merge($current_env, $new_vars);
$ph = proc_open($command, array(1 => array('pipe', 'w')), 
    $pipes, dirname(__FILE__), $env);

Edit: $_ENV is empty/not populated by default. $_SERVER contains so much more than env vars.

YanDatsiuk
  • 1,885
  • 2
  • 18
  • 30
Markus Hedlund
  • 23,374
  • 22
  • 80
  • 109

4 Answers4

11

Since PHP7.1 the varname can now be omitted to retrieve an associative array of all environment variables.

try getenv() https://3v4l.org/fkFoR

PHP Docs: https://www.php.net/manual/en/function.getenv.php

PATROMO
  • 1,112
  • 8
  • 11
4

Try getenv() it gets the value of an environment variable.

The $_ENV array is created only if the value of the variables_order configuration directive contains E. If $_ENV isn't available, use getenv( ) to retrieve an environment variable:

$path = getenv('PATH');

Martin Dimitrov
  • 1,304
  • 1
  • 11
  • 25
0

If you are using PHP 7.0, so getenv() is not available, and you are worried that $_ENV and $_SERVER don't contain all relevant variables, then, depending on your server security settings, you may be able to run shell_exec('printenv') to get all environment variables.

Derek Hill
  • 5,965
  • 5
  • 55
  • 74
-8

Think you got to use $_ENV argument

ennovativemedia
  • 361
  • 1
  • 7