【问题标题】:Classic ASP Intentional Wait / Delay inside Loop with Buffer Flushing带有缓冲区刷新的经典 ASP 故意等待/延迟循环内
【发布时间】:2014-04-23 00:13:20
【问题描述】:

我们有一个发送电子邮件的脚本,我们希望在消息之间有意等待n 毫秒,以免淹没服务器。我找到的asp_Wait() 有效,但没有任何输出。也就是说,当脚本完全运行完成时,它会转储到页面。

我的目标是在浏览器执行时查看每一行,以便监控脚本的进度。

我已经尝试过缓冲 ON 和 OFF,结果相同(Server 2008 R2、IIS7)。一个测试循环在循环中以 1 秒的延迟演示了这一点,它将花费 n 秒来加载页面,我在每一行上放置 Now() 以查看该循环何时执行(证明等待正在工作),但在脚本执行期间我没有看到单行输出。

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

感谢您的帮助!

【问题讨论】:

    标签: vbscript asp-classic


    【解决方案1】:

    我相信 IIS7 的默认配置会启用 GZIP 压缩。启用压缩后,ASP 倾向于忽略 Response.Flush() 语句。

    尝试按照说明 here 禁用压缩,看看是否有帮助。

    编辑:也找到了this

    【讨论】:

      【解决方案2】:

      我喜欢让客户端通过重定向到如下所示的页面来处理延迟:

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

      【讨论】:

        猜你喜欢
        • 2023-03-04
        • 1970-01-01
        • 2016-11-19
        • 1970-01-01
        • 1970-01-01
        • 2013-09-26
        • 1970-01-01
        • 1970-01-01
        • 2018-08-04
        相关资源
        最近更新 更多