I am interested to know what exactly passthru() is doing?
I have to create my own function with similar functionality, but I cannot understand how the function works.
I am interested to know what exactly passthru() is doing?
I have to create my own function with similar functionality, but I cannot understand how the function works.
The internals of passthru
won't help you much, since they're too low-level to be reproducible by PHP.
My goal is to forward the output to any arbitrary file, not just php://stdout.
If you want to do this on PHP level without first reading the whole output into a variable, I'd suggest something like popen
. This lets you open a pointer to a process, from which you can read little by little and write the data to a file little by little (which is actually probably pretty close to what passthru
does). E.g.:
while (($buffer = fread($p, 1024)) !== false) {
fwrite($file, $buffer);
}
If you're working on the command line anyway though, why not just write to a file there?
exec('command > file');