Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ff8041

Browse filesBrowse files
[Process] Dont rely on putenv(), it fails on ZTS PHP
1 parent 50644d0 commit 0ff8041
Copy full SHA for 0ff8041

File tree

2 files changed

+29
-20
lines changed
Filter options

2 files changed

+29
-20
lines changed

‎src/Symfony/Component/BrowserKit/Client.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Client.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ protected function doRequestInProcess($request)
343343
{
344344
$deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
345345
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
346+
$_ENV['SYMFONY_DEPRECATIONS_SERIALIZE'] = $deprecationsFile;
346347
$process = new PhpProcess($this->getScript($request), null, null);
347348
$process->run();
348349

‎src/Symfony/Component/Process/Process.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Process.php
+28-20Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,14 @@ public function start(callable $callback = null/*, array $env = array()*/)
304304
$inheritEnv = true;
305305
}
306306

307-
$envBackup = array();
308307
if (null !== $env && $inheritEnv) {
309-
foreach ($env as $k => $v) {
310-
$envBackup[$k] = getenv($k);
311-
putenv(false === $v || null === $v ? $k : "$k=$v");
312-
}
313-
$env = null;
308+
$env += $this->getDefaultEnv();
314309
} elseif (null !== $env) {
315310
@trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
316311
}
317312
if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
318313
$this->options['bypass_shell'] = true;
319-
$commandline = $this->prepareWindowsCommandLine($commandline, $envBackup, $env);
314+
$commandline = $this->prepareWindowsCommandLine($commandline, $env);
320315
} elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
321316
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
322317
$descriptors[3] = array('pipe', 'w');
@@ -332,10 +327,6 @@ public function start(callable $callback = null/*, array $env = array()*/)
332327

333328
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $this->options);
334329

335-
foreach ($envBackup as $k => $v) {
336-
putenv(false === $v ? $k : "$k=$v");
337-
}
338-
339330
if (!is_resource($this->process)) {
340331
throw new RuntimeException('Unable to launch a new process.');
341332
}
@@ -1623,7 +1614,7 @@ private function doSignal($signal, $throwException)
16231614
return true;
16241615
}
16251616

1626-
private function prepareWindowsCommandLine($cmd, array &$envBackup, array &$env = null)
1617+
private function prepareWindowsCommandLine($cmd, array &$env)
16271618
{
16281619
$uid = uniqid('', true);
16291620
$varCount = 0;
@@ -1636,7 +1627,7 @@ private function prepareWindowsCommandLine($cmd, array &$envBackup, array &$env
16361627
[^"%!^]*+
16371628
)++
16381629
) | [^"]*+ )"/x',
1639-
function ($m) use (&$envBackup, &$env, &$varCache, &$varCount, $uid) {
1630+
function ($m) use (&$env, &$varCache, &$varCount, $uid) {
16401631
if (!isset($m[1])) {
16411632
return $m[0];
16421633
}
@@ -1654,13 +1645,7 @@ function ($m) use (&$envBackup, &$env, &$varCache, &$varCount, $uid) {
16541645
$value = '"'.preg_replace('/(\\\\*)"/', '$1$1\\"', $value).'"';
16551646
$var = $uid.++$varCount;
16561647

1657-
if (null === $env) {
1658-
putenv("$var=$value");
1659-
} else {
1660-
$env[$var] = $value;
1661-
}
1662-
1663-
$envBackup[$var] = false;
1648+
$env[$var] = $value;
16641649

16651650
return $varCache[$m[0]] = '!'.$var.'!';
16661651
},
@@ -1728,4 +1713,27 @@ private function escapeArgument($argument)
17281713

17291714
return '"'.str_replace(array('"', '^', '%', '!', "\n"), array('""', '"^^"', '"^%"', '"^!"', '!LF!'), $argument).'"';
17301715
}
1716+
1717+
private function getDefaultEnv()
1718+
{
1719+
if (\PHP_VERSION_ID >= 70100) {
1720+
$env = getenv();
1721+
} else {
1722+
$env = array();
1723+
1724+
foreach ($_SERVER as $k => $v) {
1725+
if (is_string($v) && false !== $v = getenv($k)) {
1726+
$env[$k] = $v;
1727+
}
1728+
}
1729+
}
1730+
1731+
foreach ($_ENV as $k => $v) {
1732+
if (is_string($v)) {
1733+
$env[$k] = $v;
1734+
}
1735+
}
1736+
1737+
return $env;
1738+
}
17311739
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.