Solved

Unbuffered PHP output in browser using Nginx as web server

Posted on 2013-11-05
5
559 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 109

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 109

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 109

Expert Comment

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

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

840 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