doc-en icon indicating copy to clipboard operation
doc-en copied to clipboard

Clarify how proc_open() handles simple filenames

Open gqqnbig opened this issue 1 year ago • 0 comments

$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:

  1. Specify that proc_open calls posix_spawnp or execvp: Curious developers can then read the documentation of posix_spawnp or execvp to know the exact logic of executable searching.

  2. Specify that proc_open uses the PATH environment variable to execute short filenames, or use the directories returned by confstr(_CS_PATH) when the PATH environment variable is not set: This way you avoid mention posix_spawnp or execvp.

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.

gqqnbig avatar Jul 13 '24 07:07 gqqnbig