php function to get data from a stream

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prad87
Forum Newbie
Posts: 3
Joined: Tue Feb 09, 2010 1:44 pm

php function to get data from a stream

Post 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??
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: php function to get data from a stream

Post 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.
Post Reply