Date:  02/20/2002 03:38:29 PM Msg ID:  000383
From:  D.B. Stepp Thread:  000369
Subject:  Re: Script Timeouts
Thanks for the info.  Your example works perfectly on my server, but with the few changes I've made it seems to stop working.

I have a table that contains a field that stores a filename if that file exists on the harddrive.  In my example, I have a table in c:\temp\ called "example.dbf" and it contains one character field, "filename".  I need to check 9 different directories for each filename and I want to check for 1.jpg through 180.jpg.  Also, the table has 180 blank records in it.

Even if I use Server.AddScriptTimeout(60) in the loop, since it will never take a full minute, it still times out.  However, if I go to the Control Center and change the script timeout there to something larger like 999, it runs just fine.

However, I thought simply adding "Server.SetScriptTimeout(2000)" at the beginning would be all that was needed since this script doesn't take anywhere near 1/2 hour.

Thanks,
DB

<%
Response.Buffer = .F.
* Silly work-around to IE buffering problem
Response.Write(REPLICATE(" ", 255))
Server.SetScriptTimeout(2000)
StartTime = DATETIME()
Response.Write(TTOC(StartTime) + "<br>")
USE c:\temp\example.dbf
SELECT example
FOR i = 1 TO 180
replace all filename with alltrim(str(i)) + '.jpg' for file('c:\temp1\' + alltrim(str(i)) + '.jpg')
replace all filename with alltrim(str(i)) + '.jpg' for file('c:\temp2\' + alltrim(str(i)) + '.jpg')
replace all filename with alltrim(str(i)) + '.jpg' for file('c:\temp3\' + alltrim(str(i)) + '.jpg')
replace all filename with alltrim(str(i)) + '.jpg' for file('c:\temp4\' + alltrim(str(i)) + '.jpg')
replace all filename with alltrim(str(i)) + '.jpg' for file('c:\temp5\' + alltrim(str(i)) + '.jpg')
replace all filename with alltrim(str(i)) + '.jpg' for file('c:\temp6\' + alltrim(str(i)) + '.jpg')
replace all filename with alltrim(str(i)) + '.jpg' for file('c:\temp7\' + alltrim(str(i)) + '.jpg')
replace all filename with alltrim(str(i)) + '.jpg' for file('c:\temp8\' + alltrim(str(i)) + '.jpg')
replace all filename with alltrim(str(i)) + '.jpg' for file('c:\temp9\' + alltrim(str(i)) + '.jpg')
    Response.Write(STR(DATETIME() - StartTime) + " seconds<br>")
NEXT
Response.Write("Done!<br>")
%>



Sent by FoxWeb Support on 02/16/2002 02:37:51 PM:
The SetScriptTimeout and AddScriptTimeout methods of the Server object do not have 999 as the upper limit.  If you wish you can use 1200, which will give you 20 minutes.

Use SetScriptTimeout in cases where you either know in advance how long a script will take, or the delay is caused by a single statement (such as a long query), which will prevent you from using AddScriptTimeout.  Use AddScriptTimeout in cases where the delay is caused by multiple commands -- especially with long loops.

Here's some sample code, which illustrates the use of SetScriptTimeout.  If you wanted you could also use Server.AddScriptTimeout(10) within the FOR/NEXT loop.  This would be especially useful if you didn't know how many iterations you would eventually end up with.

<%
Response.Buffer = .F.
* Silly work-around to IE buffering problem
Response.Write(REPLICATE(" ", 255))
Server.SetScriptTimeout(2000)
StartTime = DATETIME()
Response.Write(TTOC(StartTime) + "<br>")
FOR i = 1 TO 180
    WAIT '' TIMEOUT 10
    Response.Write(STR(DATETIME() - StartTime) + " seconds<br>")
NEXT
Response.Write("Done!<br>")
%>

FoxWeb Support Team
support@foxweb.com