Solved

Unbuffered PHP output in browser using Nginx as web server

Posted on 2013-11-05
5
569 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 total points
ID: 39624093
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
ID: 39624159
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 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39624267
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
ID: 39634582
Thanks for the tips and the excellent Ajax article.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39634777
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 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