Jump to content

script passing stdout directly to browser


hvle

Recommended Posts

Hi guys,

 

I have a script running on linux.  This script spit out text (stdout) as it run.  I want this text to pass directly to browser.  I used passthru command to execute the script but browser will wait until this php script finished then display all the output at once.

 

Is there a way to achieve this?

 

thanks

Link to comment
Share on other sites

You can try ob_implicit_flush(1)

 

This will not be enough if your webserver is compressing output though, so you must also ensure that zlib is not set to compress output in php.ini, and that mod_gzip is not active in the webserver.

 

It's not enough to disable zlib after your script starts in my experience.

Link to comment
Share on other sites

Ajax: will not solve this

 

Some experience I like to share:

This is the output buffering in PHP, as btherl pointed out.  I wouldn't want to change the good ini settings to get this work.  If that's not the case, you can follow btherl instruction.

 

I found that using ob_flush() and flush() can be somewhat help, although not ideally solve my problem.

Link to comment
Share on other sites

Ajax can be used as well to achieve what you want.  We use this at my workplace to regularly refresh output from a script.

 

We also use ob_implicit_flush() for other applications.

 

I believe the sajax method is more robust, as ob_implicit_flush() can fail for the various reasons listed in my earlier post.  Some browsers will also not display anything until a certain amount of data is received, so you may have to start by printing some junk if you want to use the ob_implicit_flush() approach.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.