Reported by Patrick Georgi, Aug 20, 2011
I need to call a program which accepts its data via stdin. To avoid having to build shell scripts on the fly that wrap this program (and finally delete themselves), I extended the renderer to accept php file URIs (including php://stdin, which is important for me), create a temporary file, push its content to the program and finally delete the temporary file. See attached patch.
Comment 1 by Thomas Keller, Aug 21, 2011
Basically looks good, a few minor nitpicks: * consider using $cfg['tmp_folder'] instead of '/tmp' (to which you could however fallback) * if ($this->infile) is a bit too generic for my taste, better test for null explicitely * error handling in case file_get_contents($this->infile) fails * error handling in case file_put_contents() failed and as such a later unlink($name) fails as well * temp file is not removed in case passthru fails Pluf's error handler that gets triggered on notices for any of the IO functions probably does the rest, but I'm always a bit dubious about cleaning up the mess properly when it breaks.
Comment 2 by Patrick Georgi, Aug 21, 2011
The new version uses proc_open, eliminating the issues regarding /tmp and temp files (no temp files in the first place). $this->infile is now tested explicitely, the file_get/put_contents related code is entirely different now.
Comment 3 by Patrick Georgi, Aug 21, 2011
Forgot to note: * tested with stdin (git repository access in IDF) * tested without stdin (git zip export) * not tested with mod_php, but with php via FastCGI (might make a difference with proc_open)