Solved

Unbuffered PHP output in browser using Nginx as web server

Posted on 2013-11-05
5
550 Views
Last Modified: 2013-11-08
Is it possible to configure Nginx to run a PHP script but NOT buffer the output.

e.g. to output the following with numbers showing in the browser every second

for ($i = 1; $i <=10; $i++) {
      echo "$i<br>";
      sleep(1);
}

BT
0
Comment
Question by:brothertom
  • 3
  • 2
5 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 total points
Comment Utility
Maybe, but there are a lot of issues that you will encounter along the way.  PHP offers flush() to help with this.  You want to read the user-contributed notes carefully.  Flush() means nothing to small output documents.  You may also encounter buffering in the client browser.  Some hosting companies make it impossible to turn off output buffering (which actually makes a bit of sense from a performance standpoint).

If you can tell us from a high-level, non-technical view exactly what you're trying to achieve we may be able to offer some ideas.
0
 

Author Comment

by:brothertom
Comment Utility
Thanks Ray - points noted.

Essentially, I want to allow the user to post in several hundred lines, of shall we say 'commands', into a textbox (newline delim), then on clicking the Process button, see the results of each 'command' on the web page as they happen (each command could take a second or two).

Buffering would have been easy because I could just echo the results to the output.

I guess I would get more complex and use JS to read each line, make an Ajax call, then display the results of each call by stuffing the DOM, but just a bit too complex for this minor project.

BT
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
jQuery makes the whole AJAX thing a lot easier, and from your description, that would be the way to go, I think.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
0
 

Author Closing Comment

by:brothertom
Comment Utility
Thanks for the tips and the excellent Ajax article.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now