php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50503 proc_open loses constants with $env
Submitted: 2009-12-17 00:40 UTC Modified: 2009-12-31 18:01 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: tidustracker at freenet dot de Assigned: pajoye
Status: Assigned Package: Program Execution
PHP Version: 5.3.1 OS: win32 only - Windows Vista
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-12-17 00:40 UTC] tidustracker at freenet dot de
Description:
------------
It seems that passing an array(filled or empty) to proc_open drops the two constants SOL_TCP and SOL_UDP in created process

Reproduce code:
---------------
$arrConstants = get_defined_constants(true);

print('Constants: '. count($arrConstants['sockets']) . PHP_EOL);
print_r($arrConstants['sockets']);

ob_start(); ?>
	$arrConstants = get_defined_constants(true);

	file_put_contents('D:/proc_open_bug.txt', 'Constants: '. count($arrConstants['sockets']) . PHP_EOL . print_r($arrConstants['sockets'], true));
<?php
	$strCode = ob_get_contents();
ob_end_clean();

$arrDescriptor 	= array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
$arrOptions		= array('suppress_errors' => false, 'bypass_shell' => true);
$arrPipes		= array();
$strCWD			= null;
$arrEnv			= array('process' => true); // Constants SOL_TCP and SOL_UDP are NOT available in opened process
#$arrEnv		= null;						// All fine with constants SOL_TCP and SOL_UDP

proc_open('php_53 -r "'. $strCode. '"', $arrDescriptor, $arrPipes, $strCWD, $arrEnv, $arrOptions);

Expected result:
----------------
passing an array to proc_open expects 86 constants including SOL_TCP and SOL_UDP in the new process

Actual result:
--------------
only 84 constants

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-17 01:01 UTC] pajoye@php.net
Please provide a valid/working script.

The easiest way to verify that all ENVs are correctly defined is to simply echo them out (echo %ENVNAME%).
 [2009-12-17 01:22 UTC] tidustracker at freenet dot de
The script is working very well? Adjust the two paths and run it in CLI. The ENVs are not the problem, the ENVs cause the problem.

The php example code starts via proc_open a new php process.
With an passed $env array to proc_open, the two constants SOL_TCP and SOL_UDP described at http://php.net/manual/en/sockets.constants.php are missing in the new php process.
 [2009-12-17 01:31 UTC] pajoye@php.net
but that's not a proc_open bug then. PHP has no idea about what has called it. I'm not sure either why they are not defined in this case.


 [2009-12-19 13:23 UTC] carsten_sttgt at gmx dot de
> but that's not a proc_open bug then.

Correct, but I think it there a basic problem with proc_open on Windows. In this case with the environment.

Just see this example:
http://de.php.net/manual/en/function.proc-open.php#function.proc-open.examples

It's not working on Windows (returning 1 and no output). If you change:
- $process = proc_open('php', $descriptorspec, $pipes, $cwd, $env);
+ $process = proc_open('php', $descriptorspec, $pipes);

it's "working". But also no output, because the environment $_ENV is empty (even the new process should inherit the current ENV).

if you now change:
- write($pipes[0], '<?php print_r($_ENV); ?>');
+ write($pipes[0], '<?php print_r($_SERVER); ?>');

you can see there is an output. But as long $env is an array (and not null) the script is not working). And so it's also not possible to define new env variables for the new process.

Regards,
Carsten
 [2009-12-28 14:55 UTC] pajoye@php.net
Will take a look early in January for 5.3.2
 [2011-08-18 06:50 UTC] augf87 at gmail dot com
I´m having the same problem. Same conditions and same results. I´m using PHP 5.3.5, os Windows XP 32bit.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC