Solved

Stop running script

Posted on 2001-06-08
14
275 Views
Last Modified: 2007-12-19
Hi,
I have an ASP search script that runs for too long.  Is there any way to stop the script once it has started?  I do not have access to change the server.scripttimeout default value and 90 seconds is way to long.  I have tried a stop button that would spark a response.end if statement but once the script is started it will not even let you get back to the page.  
Thanks
0
Comment
Question by:theywanttheworld
  • 2
  • 2
  • 2
  • +6
14 Comments
 

Accepted Solution

by:
HabBoy earned 200 total points
Comment Utility
Not sure if this is what you are looking for but you could put a timed loop in and when your condition is met you would do this:

Response.Clear
Response.End
0
 

Expert Comment

by:dlillibridge
Comment Utility
Call the Server.ScriptTimeout = NumSeconds
command and set the script timeout just for that specific page.
0
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
No script should take 90 seconds to run.  period.  If it really takes this long for a script to load and run, it's time to rebuild the scripts.

What is this code doing?  Are you taking advantages of subs and Functions calls?  You can always put an Exit in your code to stop functions and sub commands;
The Exit statement allows you to exit from inside a block of code such as a conditional statement (Do ...Loop, For ... Next, For Each ... Next) or a procedure (Function, Sub) before it would normally be completed.
 

 
This allows you to exit from inside a Do Until ... Loop.
 
Code:
<% Exit Do %>
 

 
This allows you to exit from inside a Do While ... Loop.
 
Code:
<% Exit Do %>
 
This allows you to exit from inside a For ... Next.
 
Code:
<% Exit For %>
 
This allows you to exit from inside a For Each ... Next.
 
Code:
<% Exit For %>
 
This allows you to exit from inside a Function.
 
Code:
<% Exit Function %>
 
This allows you to exit from inside a Sub.
 
Code:
<% Exit Sub %>

... post the script sommewhere so we can see if it can be streamlined.
0
 
LVL 2

Expert Comment

by:_marko_
Comment Utility
mqfranz:
> No script should take 90 seconds to run.  period.

I beg to differ. I had to write write a search engine for some AutoCAD files a year back. The engine was not a big deal, but the process of updating the database was. When updating it would have to browse through two directories with tens of thousands of files each, check the file names with all those existing in the database. If the file had been deleted then it must be deleted from the database and if a file had been added to the directory then the reference must also be added to the database. I used 16 000 files to simulate the process.

At first I tried to delete all the entries from the database and to add the whole directory every time. It was the fastest way, but it bloated the database and after a few testruns it was >30 Mb in size. That solution was no good so I hit my head against the wall a couple of times and finally I had a working algorithm. At first the process took approximately 5 hours but after 'some' streamlining I got it down to 3 minutes on a regular PC without bloating the database. I was satisfied :-)

Anyway, the point of this story was, that there are scripts which have execution times past 90 seconds.


As for the question at hand,

theywanttheworld:
I don't really have any suggestions, but I'd say that if dlillibridge's answer isn't right you should explain the problem a little closer.

-Marko
0
 
LVL 5

Expert Comment

by:dgorin
Comment Utility
I don't quite understand, do you want to interrupt the correctly running script so it doesn't finish, or does the script get off in left field somewhere?

I'm with mqfranz, any asp script that takes 90+ seconds to run normally is not acceptable.  Such a script will time out without completing on most web servers.  Some kind of architectural change should be made.

If there is a problem with the script that makes it run too long, post the code here & maybe someone can see the problem.

0
 
LVL 7

Expert Comment

by:weesiong
Comment Utility
HadBoy is correct, using Response.Clear, Response.End :o

Regards,
Wee Siong
0
 
LVL 5

Expert Comment

by:Kelmen
Comment Utility
You should elaborate more on "Why you want to Stop the scripting once it's executed"? Is it's because you just testing some something?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:melio
Comment Utility
theywanttheworld,

i got this from the msdn library:

End
The End method causes the Web server to stop processing the script and return the current result. The remaining contents of the file are not processed.

Syntax
Response.End

Remarks
If Response.Buffer has been set to TRUE, calling Response.End will flush the buffer. If you do not want output returned to the user, you should call Response.Clear first.

<%
  Response.Clear
  Response.End
%>

i still encourage having the code posted here. thanks!
0
 

Expert Comment

by:melio
Comment Utility
theywanttheworld,

i got this from the msdn library which is very similar to habboy's comment/suggestion:

End
The End method causes the Web server to stop processing the script and return the current result. The remaining contents of the file are not processed.

Syntax
Response.End

Remarks
If Response.Buffer has been set to TRUE, calling Response.End will flush the buffer. If you do not want output returned to the user, you should call Response.Clear first.

<%
  Response.Clear
  Response.End
%>

i still encourage having the code posted here. thanks!
0
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
melio, lets see...

HabBoy covered the Clear/End method, and I covered the End method.

What have you got to contribute that hasn't already been covered?
0
 

Author Comment

by:theywanttheworld
Comment Utility
Thanks, I used second(now) before and and after a certain section of code and then and if statement set for 3 seconds to response.end.  

The script is a search engine script.  The reason that it takes so long to run is that is that there is a ton of folders and sub folders to go through with some large files.  I think that it got really bogged down when it hit this one particular folder.  Not anymore.

Thanks HabBoy and everyone else who helped.
0
 
LVL 7

Expert Comment

by:weesiong
Comment Utility
theywanttheworld,

Why dont try using Server.ScriptTimeOut()
<%
Server.ScriptTimeOut = 10 '10 second
.
.
%>

Regards,
Wee Siong
0
 

Author Comment

by:theywanttheworld
Comment Utility
The default server timeout is 90 seconds.  You can set in the script for any time that is above the setting on the server.  If you try to set it in the script like Server.ScriptTimeOut = 10 it will not work unless the setting on the server is 10 or less.  I don't have access to the server to manually lower the timeout value.  I found this posted numerous places on the internet.

Thanks to all.
0
 
LVL 5

Expert Comment

by:Kelmen
Comment Utility
Instead of forcefully End the program execution, why don't you set a counter for the searching limit?

Like do a counter for numbers of file searched or the seconds elapse...

Below's a sample, if you interested you may need refine the codes.

Dim sngStart

sngStart = Timer()

Do While (blnContinue)
   ...searching...
   blnContinue = CBool( (Timer() - sngStart) <= 9999 )
Loop

HTH.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ASP Syntax for IF statement 21 51
Group by correlation 4 43
replace quotes with UTF-8 character 38 66
ASP Button to clear text 4 14
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now