View Complete Thread | FoxWeb Forum Home
Search:
Date:    Msg ID:   
From:    Thread:   
Subject:   
Your assumption that simply adding a call to SetScriptTimeout or AddScriptTimeout at the top of the script should be enough to extend the timeout is correct.  I have absolutely no idea why it fails to do the trick in your programs.

It would be very helpful if you could create a concise version of your script (preferably one that does not rely on any particular directory structure, or files) and posted it here.  We will take a look at it and try to find the problem.

FoxWeb Support Team
support@foxweb.com

Sent by D.B. Stepp on 02/21/2002 09:56:44 AM:
I'm a little stumped, to be honest.

I set my script timeout in the Control Center to 30 seconds.  I then went into one of my long running scripts that takes between 2 to 3 minutes and added to the second line of the script Server.SetScriptTimeout with values of 90, 120, 150 & 180.  All four tests stopped at 30 seconds.

I then used your suggestion and stored the execution time and, during a few different loops, added a check to see if the script was about to timeout.  I set the Server.AddScriptTimeout with values of 10, 20, 30 & 60 seconds.  All four tests stopped at 30 seconds.

I then added Server.AddScriptTimeout before each section of the script that I knew would take a little longer.  (This time I didn't check to see if the script was going to timeout.)  Again I used values of 10, 20, 30 & 60 seconds.  All four tests stopped at 30 seconds.  I then changed Server.AddScriptTimeout to Server.SetScriptTimeout and re-ran the test and again they all stopped at 30 second. 

I then removed all that code, went into the Control Center and changed the value from 30 to 180.  I re-ran the script and it worked perfectly.  I set the Control Center back to 30 and cut n' pasted your first example exactly as you had it, re-ran that with Server.SetScriptTimeout set to 90, 120, 150 & 180 and they all worked perfectly.

Am I doing something wrong with Server.AddScriptTimeout and Server.SetScriptTimeout?  I seems to me that simply adding a Server.SetScriptTimeout(180) at the top of a script is all that is needed to extend the timeout.

Regards,
DB

PS - Thanks for the ADIR()/ASCAN() tip.  While it didn't solve this particular problem, it sure did speed things up. :)

Sent by FoxWeb Support on 02/20/2002 06:13:27 PM:
I see no reason why a call to SetScriptTimeout at the beginning of your script would not work.  I have a couple of suggestions:

Instead of using the FILE() function to check for the existence of a file, use the ADIR() function to retrieve the contents of a directory to an array and then use the ASCAN() function to search the array itself.  This will most certainly be faster than calling FILE() 180 times.

If you want, you can store the execution start time at the beginning of the script.  During the loop, compare the start time with the current time, and if the script is about to time out, you can add more time with the SetScriptTimeout method.  This will keep your timeouts more realistic and will avoid the need to use unnecessarily long timeout values for your scripts.

FoxWeb Support Team
support@foxweb.com

Sent by D.B. Stepp on 02/20/2002 03:38:29 PM:
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