note 57456 deleted from function.proc-open by cmb

From: Date: Sun, 01 Dec 2019 09:08:45 +0000
Subject: note 57456 deleted from function.proc-open by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213340@lists.php.net to get a copy of this message
Note Submitter: Chapman Flack ---- One can learn from the source code in ext/standard/exec.c that the right-hand side of a descriptor assignment does not have to be an array ('file', 'pipe', or 'pty') - it can also be an existing open stream. <?php $p = proc_open('myfilter', array( 0 => $infile, ...), $pipes); ?> I was glad to learn that because it solves the race condition in a scenario like this: you get a file name, open the file, read a little to make sure it's OK to serve to this client, then rewind the file and pass it as input to the filter. Without this feature, you would be limited to <?php array('file', $fname) ?> or passing the name to the filter command. Those choices both involve a race (because the file will be reopened after you have checked it's OK), and the last one invites surprises if not carefully quoted, too.

« previous php.notes (#213340) next »