Domanda

We have a script that sends emails and we want an intentional wait for n milliseconds between messages to not flood the server. The asp_Wait() I found works but without any output. That is, when the script is completely done running it dumps to the page.

My goal is to view each line in a browser as it is executed so I can monitor the progress of the script.

I have tried both with buffering ON and OFF with the same curious result (Server 2008 R2, IIS7). A test loop demonstrates this with a 1-second delay in the loop it will take n seconds to load the page, and I am putting Now() on each line to see when that loop executing (proving the wait is working), but I do not see a single line outputted during the script's execution.

<%
Dim IsBuffer ' this allows easy toggling of the buffer feature
    IsBuffer = False
If IsBuffer Then Response.Buffer = True End If
Server.ScriptTimeout=7200  ' 2 hours (yes this is overkill!!)

i = 0
Response.Write "<h2>Test Page</h2><hr>"
If IsBuffer Then Response.Flush() End If ' flush the header

while i < 20
    i = i + 1
    Response.Write i & " at: " & Now() & "<br />" & VbCrLf
    If IsBuffer Then Response.Flush() End If
    Call asp_Wait(1000) ' milliseconds  
wend

Response.Write "<br /><strong>**TOTAL OF " & i & " LOOPS.**</strong><br />" & vbCrLf

Sub asp_Wait(nMilliseconds)
  Dim oShell
  Set oShell= Server.CreateObject("WScript.Shell")
  Call oShell.run("ping 1.2.3.4 -n 1 -w " & nMilliseconds,1,TRUE)
End Sub
%>

Thanks for your help!

È stato utile?

Soluzione

I believe the default configuration for IIS7 enables GZIP compression. With compression enabled, ASP tends to ignore Response.Flush() statements.

Try following the instructions here to disable compression and see if that helps.

Edit: Found this as well.

Altri suggerimenti

I like to let the client handle delays by using redirect to a page that looks like this:

<%
ID_template= request.querystring("ID_template")
s_resume=request.querystring("resume")
s_file = "admin_email_send_go.asp?ID_template=" & ID_template
if (s_resume="yes") then s_file = "admin_email_send_resume.asp?ID_template=" & ID_template
%>
<html>
<head>
<meta http-equiv="Refresh" content="<%=int(session("n_records")/50)%>; url=<%=s_file%>">
    <script type="text/javascript">
    <!--
    function delayer(){
    document.location = "<%=s_file%>"
    }
    //-->
    </script>
</head>
<body onLoad="setTimeout('delayer()',<%=int(session("n_records")*20)%>)" bgcolor='#FFFFFF'>
<br>
<table width='100%' height='100%'>
<tr>
<td valign=middle align=center>
    <table border=1>
    <tr>
    <td>
        Total list size: <%=session("n_records")%><br>
        Sent so far: <%=session("n_records_sent")%>
    </td>
    </tr>
    </table><br>
    <br>
    Sending next group of <%=application("email_group_size")%> in 2 seconds.<br>
    Please wait...<br>
    <br>
    If you want to quit or pause the process at any time, click <a href='admin_email_send.asp?ID_template=<%=ID_template%>'>here</a>.<br>
    <br>
</td>
</tr>
</table>
</body>
</html>

This code worked best for me:

<%
Private Function Delay(intSeconds)
    StartTimed = Now()
    CurrentTimed = Now()
    While DateDiff("s",StartTimed,CurrentTimed) < intSeconds
    CurrentTimed = Now()
    Wend
End Function

Response.Write("This is now<br>")
call Delay(10)
Response.Write("This is 10 seconds later<br>")
%>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top