Page 1 of 1

php function to get data from a stream

Posted: Mon Apr 26, 2010 2:55 pm
by prad87
i have a shell script running on a machine and it generates lot of output for about a few mins.
i need a php function to retrieve the output instantaneously, i tried stream_get_contents but it gave me the entire output once script finsihed executing.

any ideas guys??

Re: php function to get data from a stream

Posted: Mon Apr 26, 2010 3:57 pm
by davex
Hi,

Are you executing the shell script from within your PHP? I'm guessing not and you want to read from a file.

Firstly - is the output being written to the file as it happens e.g. if you sit in a shell typing the output file does it show output.

If so what I'd suggest is using fopen() and then fgets() with a size parameters e.g. reading 1k in at a time and then processing that in turn.

What will happen when it "overtakes" the shell script output and gets to the end of the file I'm not sure but I'd have thought wait as there is no EOF. Maybe. But maybe not.

HTH,

Cheers,

Dave.