|
Posted by Chapman Flack on 11/24/12 11:28
Joshie Surber wrote:
> i don't see what your problem is here -- you are printing something on
> the page, right?
The point was, the content is produced by an external program. The PHP
script needs to output the headers and then exec the program to
produce the content. The program is a filter that reads from a file
PHP has already opened and writes content to stdout. (I should mention
this hosting service runs PHP in CGI mode.) In another language, the
right way to do it would be to exec(2) - pcntl_exec in PHP speak - the
filter, with the open file dup'd on its standard input. exec /replaces/
PHP with the filter, so if PHP hasn't written the headers by then, it
never will. Another approach that's almost as good would be popen; the
PHP script would have to spoon-feed the file contents down the filter's
input pipe, but the output goes to stdout. Won't work in PHP either,
without some way to let PHP know it needs to spit out the headers
because output is about to happen.
proc_open could be used, if there were a way to associate file
descriptor 0 with the current fd of an already open file. But if
there is, it isn't documented. Is there a way?
I got something working with passthru, which doesn't have any way to
inherit an open descriptor, so the filter had to be rewritten to take
the file name as an argument, properly escaped of course, and then
reopen it, which only works because the input in this case does happen
to be a regular file, and still creates an unavoidable race condition.
Why does the least efficient and least secure way of doing a simple
task
turn out to be the only way possible in PHP? Have I missed anything in
the docs?
Navigation:
[Reply to this message]
|