Jump to content

output buffer control


drkstr

Recommended Posts

Hello,

I need to be able to run some system commands and scripts which will have a lot of output. I would like to be able to not just it all dump to the screen in a long scrolling list. Is there some way to control the output and have it do things like when it reaches the max allowed lines, it just starts shifting up, erasing the top?

I'm not afraid of reading, but I'm not sure where to start. Can someone point me in the right direction?

Thanks!
...drkstr

PS: I would also like to build a "shell consol" form that simulates a system shell in the browser. This will not happen until further down the road, but if anyone has any ideas about how to attack this problem, I would really like to hear them. Thanks again!
Link to comment
https://forums.phpfreaks.com/topic/19100-output-buffer-control/
Share on other sites

[quote author=Satria Ox41464b link=topic=106190.msg424463#msg424463 date=1156915453]
have you check http://php.net/outcontrol ?
[/quote]No I didn't. Thanks, that looks like what I was looking for.

[quote author=Jenk link=topic=106190.msg424526#msg424526 date=1156928577]
Use shell_exec() instead of system(), shell_exec() returns all output as a string instead of directly outputting.
[/quote]Awesome, thanks for the tip.

So if I understand you two correctly, I can start the output buffer with ob_start(), read the output to the command in as a string, explode it into an array of lines by prex_split'ing at "/\n/", then if count > x amount of lines, array_shift the first element off the array, then implode it back to a string and print it to the output buffer?

Thanks for the help everyone,
...drkstr
Link to comment
https://forums.phpfreaks.com/topic/19100-output-buffer-control/#findComment-82840
Share on other sites

I don't know if that will do it for me, but I could be wrong. I need to have a continual stream open for the output. It's not a command that will just run once and send some output, I need to be able to display the output in real time while the process runs. Is this even possible?

Thanks for the help!
...drkstr
Link to comment
https://forums.phpfreaks.com/topic/19100-output-buffer-control/#findComment-83239
Share on other sites

[quote]It's not a command that will just run once and send some output, I need to be able to display the output in real time while the process runs. Is this even possible?[/quote]

If your talking about attempting this within a server / browser environment then the simple answer is no. You could maybe take it on using some javascript and xhttprequest trickery, but that opens a whole new can of worms (Ajax).

The thing is, even using shell_exec() the string will not be handed to php until the command is finished proccessing. You would have to fake the [i]real time appearence[/i] and I really dont think thats what you want, nor do I see the point.
Link to comment
https://forums.phpfreaks.com/topic/19100-output-buffer-control/#findComment-83245
Share on other sites

Well from what I have read so far, I think I might be able to do it this way. (keep in mind I'm still just tossing around ideas)

I can write a shell script which starts a command and dumps the output as raw data to a file (well call it output.txt). It would over write any previous data, and delete the file when there is no more output. The PHP will run the shell script in the background, pause for a second or two, then start a while( file_exists("output.txt") ) loop which reads in the contents of the file, wraps XML tags around it, and makes it available as an XML object to the AJAX client script. The client side would then grab an update of the XML object being hosted on a predefined interval depending on the available bandwidth.

Does this sound doable at all? Maybe there is an easier way?

Thanks,
...drkstr
Link to comment
https://forums.phpfreaks.com/topic/19100-output-buffer-control/#findComment-83614
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.