Jump to content

Timeout for current action.


Spyderco
 Share

Recommended Posts

Hi everyone ;)

I'll explain what I'm trying to achieve briefly:

I run several websites and am running pilots for a new framework on a few server.
I have a certain script set us like a bunch of checkboxes, one of which checks a URL for it's status response set to a $ClientURL variable.
So I have something like the following:

Set includes
Set variables (one of which is $ClientURL = ("www.example.com").
Start loop
   Main script
      If $ClientURL = ("www.example.com") Then
          $ClientURL = ("www.a.com")
      If $ClientURL = ("www.a.com") Then
         $ClientURL = ("www.b.com")
      ElseIf $ClientURL = ("www.b.com") Then
         $ClientURL = ("www.c.com")
      ElseIf $ClientURL = ("www.c.com") Then
         $ClientURL = ("www.d.com")
      ElseIf $ClientURL = ("www.c.com") Then
         $ClientURL = ("www.example.com")
      Sleep until the script restarts the loop.
End loop

This only uses one main script and changes the variables needed to run in by the following value every time.
My problem is this...
Everything runs smoothly, but if a webserver takes too long to respond, the program will timeout.
This doesn't give a certain status, so it doesn't get logged by the script so it can move on to the next one.
It just freezes and crashes on it eventually.
Is there a way to add a certain timeout to a line?
Lets say something like this:

Func A ()
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", $ClientURL, False)
$oHTTP.Send()
If the time it takes = >10 seconds
   Move on to the next line
Else
   Do nothing
EndFunc

I thought about making a variable that tracks the system time in seconds that has passed by and resets it at the beginning of every new function,
but I was hoping there'd be something more efficient...
Thanks in advance guys! :)

Edited by Spyderco
Didn't complete the post yet.
Link to comment
Share on other sites

9 minutes ago, InunoTaishou said:

We have no idea what you're trying to achieve....

Is there a question in there? Because your title and description don't match up.

 

4 minutes ago, SadBunny said:

I suspect you lost part of your post there Spyderco :) 


Yeah, sorry... Got posted even though I wasn't finished typing it yet.
Edited it now ;)

Link to comment
Share on other sites

Idk much about http requests, I just use inet and curl but I think you want this member of the http object

https://msdn.microsoft.com/en-us/library/windows/desktop/aa384061(v=vs.85).aspx

So it might look like

Func A()
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", $ClientURL, False)
    $oHTTP.SetTimeouts(ResolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout) ; Adjust your timeouts accordingly
    $oHTTP.Send()
    
    ; Idk what the status value is on a successful http request
    If ($oHTTP.Status <> ???) Then
        Move on to the next line
    Else
        Do nothing
    EndIf
EndFunc

 

Link to comment
Share on other sites

5 minutes ago, InunoTaishou said:

Idk much about http requests, I just use inet and curl but I think you want this member of the http object

https://msdn.microsoft.com/en-us/library/windows/desktop/aa384061(v=vs.85).aspx

So it might look like

Func A()
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", $ClientURL, False)
    $oHTTP.SetTimeouts(ResolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout) ; Adjust your timeouts accordingly
    $oHTTP.Send()
    
    ; Idk what the status value is on a successful http request
    If ($oHTTP.Status <> ???) Then
        Move on to the next line
    Else
        Do nothing
    EndIf
EndFunc

 

Thanks!
This might just be what I'm looking for!

Link to comment
Share on other sites

Added the line and still got the error, it just didn't return a status, so it grabbed the status from the previous line.
However, the errors stopped now... even with the timout taken out of the script...
Guess I looked for the reason of errors in the wrong place after all.
Time to check the event logger on the webserver in this case...

Thanks for the quick feedback!
It's definately a line I'll keep using in some scripts! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...