Link to home
Start Free TrialLog in
Avatar of JCinDE
JCinDE

asked on

ASP Response.Flush doesn't work as it should

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?
Avatar of apollois
apollois

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<

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
make sure you have a <%Response.Buffer=TRUE%> at the very top of your page!

MaxOvrdrv2
//--- At the top of ur page should have:
<%
Response.Buffer = true
%>
.
.
.
.
.
.
.
.
<%
Response.Flush()
%>
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<
hehe... ;-)

MaxOvrdrv2
Avatar of JCinDE

ASKER

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.
have you tried setting the Response.Buffer to FALSE?

MaxOvrdrv2
Avatar of JCinDE

ASKER

Yes I have. The behavior is exactly the same.
wow... ok... so what is it that you are trying to do exactly? some kind of progress bar?

MaxOvrdrv2
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
Avatar of JCinDE

ASKER

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.
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
Avatar of JCinDE

ASKER

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...
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
Avatar of JCinDE

ASKER

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.
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

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

Avatar of JCinDE

ASKER

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.
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
Avatar of JCinDE

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of JCinDE
JCinDE

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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

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
yeah.. maybe it's the server setting that is causing this...

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

MaxOvrdrv2
Avatar of Gary
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