Page MenuHomePhabricator

D9938.id.diff
No OneTemporary

D9938.id.diff

diff --git a/scripts/__init_script__.php b/scripts/__init_script__.php
--- a/scripts/__init_script__.php
+++ b/scripts/__init_script__.php
@@ -52,6 +52,38 @@
ini_set($config_key, $config_value);
}
+ // Populate $_ENV. Normally, it is not populated for scripts running from
+ // the CLI. However, we need it in order to launch subprocesses with modified
+ // environments: we must pass the entire subprocess environment to functions
+ // like `proc_open()`.
+
+ // To do this, we must parse the list of variables out of phpinfo(). This
+ // is super gross. It would be nice to come up with a better way to do this.
+
+ ob_start();
+ phpinfo(INFO_ENVIRONMENT);
+ $env = ob_get_clean();
+
+ $env = preg_split('/[\n\r]/', $env);
+ $env = array_filter($env);
+
+ $env_map = array();
+ $seen_header = false;
+ foreach ($env as $key => $line) {
+ $line = explode(' => ', $line);
+ if ($seen_header) {
+ $val = getenv($line[0]);
+ if ($val !== false) {
+ $env_map[$line[0]] = $val;
+ }
+ } else if ($line[0] == 'Variable') {
+ $seen_header = true;
+ }
+ }
+
+ $_ENV = $env_map;
+
+
if (!ini_get('date.timezone')) {
// If the timezone isn't set, PHP issues a warning whenever you try to parse
// a date (like those from Git or Mercurial logs), even if the date contains

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 28, 9:16 PM (3 d, 1 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7708287
Default Alt Text
D9938.id.diff (1 KB)

Event Timeline