?
Solved

Unbuffered PHP output in browser using Nginx as web server

Posted on 2013-11-05
5
Medium Priority
?
591 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 2000 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 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