|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-12-23 13:56 UTC] kalle@php.net
[2009-12-23 14:22 UTC] carsten_sttgt at gmx dot de
[2009-12-23 15:16 UTC] pajoye@php.net
[2010-09-08 10:34 UTC] pajoye@php.net
[2010-09-08 10:35 UTC] pajoye@php.net
-Status: Assigned
+Status: Closed
[2010-09-08 10:35 UTC] pajoye@php.net
[2012-03-29 10:02 UTC] axel at zehden dot net
[2013-01-07 12:13 UTC] pajoye@php.net
[2013-01-07 12:13 UTC] pajoye@php.net
-Status: Closed
+Status: Feedback
[2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 05:00:01 2025 UTC |
Description: ------------ Hello, each program execution function: - exec() - passthru() - shell_exec() - system() - backtick operator or popen() is using the current script (working) directory as working directory for the command which is executed. Only proc_open() is using a different directory: - for apache2handler it the Apache ServerRoot - for CGI it's the php-cgi.exe directory - for FastCGI (mod_fgcid) it's also the php-cgi.exe directory On *nix (mod_fcgid) the proc_open() working directory is as expected also the script (working) directory. Regards, Carsten Reproduce code: --------------- <?php header('Content-Type: text/plain'); echo "------getcwd()---------\n"; echo getcwd()."\n\n"; echo "\n\n-------popen()---------\n"; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $cmd = 'dir'; } else { $cmd = 'ls'; } $process = popen($cmd, 'r'); while (!feof($process)) { echo fread($process, 80); } pclose($process); echo "\n\n-------passthru()------\n"; passthru($cmd); echo "\n\n------proc_open()------\n"; $descriptorspec = array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w') ); $process = proc_open($cmd, $descriptorspec, $pipes); while (!feof($pipes[1])) { echo fread($pipes[1], 80); } fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); ?> Expected result: ---------------- getcwd: C:\Apache2.2\htdocs 3 times a directory listing of: C:\Apache2.2\htdocs Actual result: -------------- getcwd: C:\Apache2.2\htdocs 2 times (popen, passthru) a directory listing of: C:\Apache2.2\htdocs 1 time (proc_open) a directory listing of: apache2handler: C:\Apache2.2 or CGI/FastCGI: C:\PHP