Clarify how proc_open() handles simple filenames
$handle = proc_open(array('xelatex', '--version'), [
0 => ["pipe", "r"],
1 => ["pipe", "w"],
2 => ["pipe", "w"],
], $pipes, null, null);
I wrote this code to run xelatex but proc_open couldn't find the executable. I guess this has something to do with the PATH environment variable. Then I run env --ignore-environment php testfile.php. With no PATH environment variable, proc_open can run ls. The behavior was quite confusing to me.
Consequently, I looked into the source code. In proc_open.c, I learned PHP uses posix_spawnp or execvp to run the array version of command, and the two Linux command posix_spawnp() and execvp() look up simple filenames in the PATH environment variable or the directories returned by confstr(_CS_PATH).
Are you willing to specify the behavior when the first element in the command array is a short filename without slashes?
I am happy with two styles of specifying the behavior:
-
Specify that proc_open calls
posix_spawnporexecvp: Curious developers can then read the documentation ofposix_spawnporexecvpto know the exact logic of executable searching. -
Specify that proc_open uses the
PATHenvironment variable to execute short filenames, or use the directories returned byconfstr(_CS_PATH)when thePATHenvironment variable is not set: This way you avoid mentionposix_spawnporexecvp.
I can help submit a pull request if you have idea how to improve the doc.
Related Work
https://github.com/php/doc-en/blob/7efec4c29a3cb6d6e7abe325a3c0d5b6024fa37c/appendices/migration83/other-changes.xml#L388-L395 mentioned proc_open may use the posix_spawn implementation. But this information is not available on the doc of proc_open.