Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Stop running script

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
theywanttheworld
Asked:
theywanttheworld
  • 2
  • 2
  • 2
  • +6
1 Solution
 
HabBoyCommented:
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
 
dlillibridgeCommented:
Call the Server.ScriptTimeout = NumSeconds
command and set the script timeout just for that specific page.
0
 
mgfranzCommented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
_marko_Commented:
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
 
dgorinCommented:
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
 
weesiongCommented:
HadBoy is correct, using Response.Clear, Response.End :o

Regards,
Wee Siong
0
 
KelmenCommented:
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
 
melioCommented:
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
 
melioCommented:
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
 
mgfranzCommented:
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
 
theywanttheworldAuthor Commented:
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
 
weesiongCommented:
theywanttheworld,

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

Regards,
Wee Siong
0
 
theywanttheworldAuthor Commented:
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
 
KelmenCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
  • 2
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now