Solved

PHP flush() not working with IIS

Posted on 2009-07-07
4
2,137 Views
Last Modified: 2013-11-10
It tried disabling all output caching and compression I could find in IIS Manager, yet the buffer flush functions are not working properly. Neither ob_flush() nor regular flush() function seem to have any result. The output data remains on the server until script finishes executing.
I searched internet for several days without any luck.
Any help will be greatly appreciated.
0
Comment
Question by:andrisv24
[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
  • 2
  • 2
4 Comments
 
LVL 3

Assisted Solution

by:laneway
laneway earned 100 total points
ID: 24798555
If you use print() followed by ob_flush() and then flush() your output should be sent to the client. However, depending on what you are trying to do the browser may not show you that data even if it has received it. And different browsers may behave differently. Can you provide more detail about what you are trying to do?

In the meantime, this code is a simple test you can use to test browser behavior:
// print and flush "hello"
print "hello"; ob_flush(); flush();
// wait 3 seconds
sleep(3);
// print and flush "world"
print " world"; ob_flush(); flush();

Open in new window

0
 

Author Comment

by:andrisv24
ID: 24798881
That's exactly what i'm trying to do send one line of output then wait and send more output. I tried both print() and echo();
I know for a fact that all output is buffered at the server and nothing goes to the client. The same script i'm using worked perfectly fine on apache server. However the IIS does not let the output through.
And unfortunately, I am forced to stick with IIS on this machine.
0
 
LVL 3

Assisted Solution

by:laneway
laneway earned 100 total points
ID: 24798978
Try this - it's a bit crazy but I've heard that it works in some cases... The server's output buffer has a maximum size. If you can fill it up, then any output that follows might be sent right away. So you print garbage first, which you will have to catch and discard, and then you use the rest of the output as desire. Here's the code (if it doesn't work, try a number higher than 4096):
// fill the output buffer (hopefully)
print str_repeat('x',4096); ob_flush(); flush();
// print and flush "hello"
print "hello"; ob_flush(); flush();
// wait 3 seconds
sleep(3);
// print and flush "world"
print " world"; ob_flush(); flush();

Open in new window

0
 

Accepted Solution

by:
andrisv24 earned 0 total points
ID: 24799058
Thanks Ianeway. I saw this one during my search tried it. Used a number as high as 40000000. all it does is take forever for page to load, but the hello and world are displayed immediately with no delay inbetween.
Apparently this question is harder than i though so i'm increasing points to 500
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
can i read my emails on lamp ftp 4 70
Code planning methods/tools? 5 56
htaccess add www, redirect to https, keep query string 17 56
php time 12 26
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.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

738 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