?
Solved

ASP Response.Flush doesn't work as it should

Posted on 2003-03-13
28
Medium Priority
?
2,385 Views
Last Modified: 2007-12-19
I'm finding the Response.Flush command doesn't always work. I can sometimes force it to work by doing something like the following:

Response.Write ProgressMessage
Response.Write Space(500)
Response.Flush
'Some time-intensive processing...
Response.Write ProgressMessage
Response.Write Space(500)
Response.Flush
'More time-intensive processing...

It's almost as if the server refuses to flush unless it has a certain amount of text in the buffer.

Is this the case? Is there a way to configure this on the web server?
0
Comment
Question by:JCinDE
[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
  • 11
  • 8
  • 3
  • +4
28 Comments
 
LVL 10

Expert Comment

by:apollois
ID: 8130911
Hi JCinDE,

>>>I'm finding the Response.Flush command doesn't always work.

Please be more specific.  How do you know it is not working?

If you get any errors, please post:
     1.     The complete error message
     2.     The line# of the error
     3.     The corresponding line of code, and previous 5 lines


Is "Response.buffer = True" the first statement in your ASP code?

Best Regards,
>apollois<
0
 
LVL 8

Expert Comment

by:bukko
ID: 8131324

I think I know what you are trying to do, which is update the page to show the current stage in the process, but I think that the reason you are having problems is more to do with the fact that the HTML is incomplete.

Are you able to split the process across several pages?
That way you can have a much nicer progress display.
You could use a progress bar, but the following example has a message similar to your own code:
(I haven't tried this code so it may be slightly incomplete)

<html>
<head>
  <script language=javascript>
    function updateProgressMessage( progMessage, nextStage ) {
      document.all.messageLabel.innerText = progMessage;
      if (progMessage=='Complete') {
        location.href = nextStage;
      } else {
        document.all.secretFrame.src = nextStage;
      }
    }
  </script>
</head>
<body>
  <div name='progMessage'
    Starting...
  </div>
  <iframe height=0 width=0 src='firstStage.asp'>
  </iframe>
</body>
</html>


This silently calls firstStage.asp which does the initial processing. Then, when this has completed, the HTML for firstPage.asp looks like the following:

<html>
  <head>
    <script language=javascript>
      function callParent() {
        window.parent.updateProgressMessage('Second stage...','stage2.asp');
      }
    </script>
  </head>
  <body onLoad='callParent()'>
  </body>
</html>

This will cause the next stage, 'stage2.asp', to be run, which will then call the next one, etc.

Is this any help?

Regards

bukko
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8131800
make sure you have a <%Response.Buffer=TRUE%> at the very top of your page!

MaxOvrdrv2
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:Phoebe_Yi
ID: 8148757
//--- At the top of ur page should have:
<%
Response.Buffer = true
%>
.
.
.
.
.
.
.
.
<%
Response.Flush()
%>
0
 
LVL 10

Expert Comment

by:apollois
ID: 8149080
Max and Phoebe_Yi,

>>>Response.Buffer = true

I'm glad to see that both of you agree with my first recommendation. <bg>

Best Regards,
>apollois<
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8151514
hehe... ;-)

MaxOvrdrv2
0
 
LVL 5

Author Comment

by:JCinDE
ID: 8203374
Sorry I went MIA there so long.

I do have 'Response.Buffer = True' at the top of the page. 'Response.Flush' does work, it just doesn't seem to work reliably. Often I find I need to flood out a bunch of spaces to get it to work. I'm perceiving this as a requirement to 'fill the buffer' before it will flush and I don't think it's supposed to do that.

I did a little 'brute force' experiment:

<%@ Language=VBScript %><%
     Response.Buffer = True

     Response.Write Now() & "<br>"
     For Iter = 1 to 10
          For Iter2 = 1 to 10000000
          Next
          Response.Write Now() & "<br>"
          Response.Flush
     Next
%>


Here are three snapshots of the results:

3/25/2003 10:18:53 AM
3/25/2003 10:18

3/25/2003 10:18:53 AM
3/25/2003 10:18:57 AM
3/25/2003 10:19:01 AM
3/25/2003 10:19

3/25/2003 10:18:53 AM
3/25/2003 10:18:57 AM
3/25/2003 10:19:01 AM
3/25/2003 10:19:05 AM
3/25/2003 10:19:09 AM
3/25/2003 10:19

As you can see, the Response.Flush command is not flushing the entire buffer and it is not even reliably flushing the buffer as more than one line was appearing at a time.
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8204093
have you tried setting the Response.Buffer to FALSE?

MaxOvrdrv2
0
 
LVL 5

Author Comment

by:JCinDE
ID: 8204127
Yes I have. The behavior is exactly the same.
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8204164
wow... ok... so what is it that you are trying to do exactly? some kind of progress bar?

MaxOvrdrv2
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8204211
when i run your code on my server here, i get a response.flush (Now() is printed) every 10 seconds or so... isn't that the proper results?

Results on my server:

03/25/2003 12:04:30 PM
03/25/2003 12:04:39 PM
03/25/2003 12:04:48 PM
03/25/2003 12:04:57 PM
03/25/2003 12:05:06 PM
03/25/2003 12:05:15 PM
03/25/2003 12:05:25 PM
03/25/2003 12:05:34 PM
03/25/2003 12:05:43 PM
03/25/2003 12:05:52 PM
03/25/2003 12:06:01 PM

MaxOvrdrv2
0
 
LVL 5

Author Comment

by:JCinDE
ID: 8204289
Yes that is the result I'd expect, but again it is not what I'm getting. For me, it flushes rather unpredictably. Sometimes more than one line appears at a time, sometimes only a partial line. Based on the code above and the expected behavior of the Response.Flush command one whole line should appear at a time several seconds apart (varying based on how long it takes your server to count to ten million)

But again, that is not what's happening for me and that is the problem I'm hoping to solve.
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8204366
that's very strange... i don't know what to tell you... have you tried this code in a page on it's own or was it part of teh same page that you were having problems with?

Which editing soft. are you using?

Which server are you running?

Maxovrdrv2
0
 
LVL 5

Author Comment

by:JCinDE
ID: 8204745
Running IIS 5.0 on Windows 2000 Server. Using Visual Interdev 6 SP5.

Seems to behave the same in any page and no matter how I configure the server. I'm thinking there's some configuration somewhere I don't know about...
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8204818
ok...

have you tried coding a page in NotePad instead? not going through V-I?? sometimes editing software causes extra code in the page that causes scripts to perform in a weird manner... although i have never heard of such things happening with Interdev, you should still give it a try... open notepad and put your code like this:

<%Response.Buffer=TRUE%>
<HTML>
<head></head>
<body>
<%
Response.Write Now() & "<br>"
    For Iter = 1 to 10
         For Iter2 = 1 to 10000000
         Next
         Response.Write Now() & "<br>"
         Response.Flush
    Next
%>
</body>
</html>

another thing to try... which should be done first! -> have you tried removing the <%@Language=VBScript%> perogative from the code??? sometimes, IIS interprets ASP commands as VBScript commands which causes erratic behaviour!

Try both, and let me know!

MaxOvrdrv2
0
 
LVL 5

Author Comment

by:JCinDE
ID: 8205267
I use the source edit mode in Visual Studio but just for the sake of argument I opened the file in notepad. There is no extra code.

I tried removing the @language line. Same results.

Interestingly when I pad the buffer it works:

Response.Write Now() & space(256) & "<br>"

If I use that line in my code it works. The threshhold is right around 250 characters and I'm guessing its actually 255 considering it's a binary 'round' number.

This is truly bizarre behavior.
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8206055
yeah.. that's truly weird behaviour... i don't know what to say... but if it works with the padding... can't you use it with the padding?

MaxOvrdrv2
0
 
LVL 8

Expert Comment

by:bukko
ID: 8206775

Maybe it's a network thing.
Is this running over a local network?
If so, what happens if you run it from a browser on the server?

bukko

0
 
LVL 5

Author Comment

by:JCinDE
ID: 8207903
Good question, bukko. I'll try that tomorrow.

MaxOvrdrv2: The problem with padding is that it, too, is unpredictable. The 256 spaces in the example above works, but in other files I seem to have to pad it out further.

And while I COULD just use 'space(1024)' in all the pages where I need to flush, I'd rather figure out why this is happening and nip it.
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8211780
true... i understand... but i can't see why it would do that... i tested the same thing on my 4 different servers here (NT 4.0, 2000, XP & Apache) and they all return the proper results... so it has to be something with the server... a setting somewhere... but i don't know what it could be... very sorry...

MaxOvrdrv2
0
 
LVL 5

Author Comment

by:JCinDE
ID: 8708569
I finally got around to trying the script above on the webserver itself to eliminate the network as a possible cause...but I still get the same results. When I response.flush, it doesn't flush EVERYTHING in the buffer.

I'm bumping the points for this question. It's a real stumper.
0
 
LVL 5

Accepted Solution

by:
JCinDE earned 0 total points
ID: 8708711
I think I've found the cause of the problem, but I am hoping there is a workaround. We have enabled HTTP Compression on both of the servers to improve performance over a very slow CDPD cellular modem connection. When I turned compression off for the test server, the buffering worked as expected. Problem is, we need compression and we need the buffering thing to work right...

It's a good thing my hair's too short to grab by the fistfull...
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8717649
ahhh.... ok... try this when you want to flush:

Response.Buffer=Nothing
Response.flush


try them both at the same time.. .and if you get an error on the Response.Flush, just take it out... if not... then leave them together... let me know what happens...

MaxOvrdrv2
0
 
LVL 8

Expert Comment

by:bukko
ID: 8748265
JCinDE,

The problem may be that IIS may be waiting for more data so it can compress more efficiently.
Maybe there is a way to set page sizes for compression, though I'm afraid I don't know what that is! :(
Might be worth looking it up, though.

bukko

0
 

Expert Comment

by:powsurfer
ID: 8816353
I am having the same problem.  Here's maybe a clue that it might be a server config problem.  When I run the script in the InterDev debugger, it works!

powsurfer
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8816623
yeah.. maybe it's the server setting that is causing this...

but couldn't help you there... sorry...

MaxOvrdrv2
0
 
LVL 58

Expert Comment

by:Gary
ID: 9350138
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ'd and pts refunded

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

770 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