Jump to content



Photo

Continuously execute PHP script with random pauses


  • Please log in to reply
5 replies to this topic

#1 pantho

pantho

    Seeker

  • New Members
  • 3 posts

Posted 24 April 2012 - 12:15 PM

Hi

I looking for AutoIt code to continuously execute PHP script with random X sec delay between starts (where X is in interval FROM-TO)

Steps:

Step 1. wait random X seconds (X in FROM-TO interval)
Step 2. execute PHP interpreter+script: "c:\php\php.exe script.php"
Step 3. if scripts exit code==0 back to step 1, else warning and stop

+ button to terminate the AutoIt script

Thanks for help.





#2 MrMitchell

MrMitchell

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 747 posts

Posted 24 April 2012 - 01:37 PM

Hi and welcome to the forums.

You should be able to find everything you need in the Help File. We'll always recommend you get started with a basic AutoIt tutorial then once you've gone through some of the examples, check out the following commands specifically:

and the section about creating custom functions.

Post what you come up with along with questions if you have trouble.

Edit: Go here if you need help with Help File and just getting started...

Edited by MrMitchell, 24 April 2012 - 01:45 PM.


#3 hannes08

hannes08

    my oh my

  • Active Members
  • PipPipPipPipPipPip
  • 930 posts

Posted 24 April 2012 - 03:01 PM

I would suggest to use Run() or RunWait() to run the php scripts, as you'ss receieve the return code.
Regards,Hannes
Spoiler

#4 pantho

pantho

    Seeker

  • New Members
  • 3 posts

Posted 25 April 2012 - 11:39 AM

Thanks for help, what do you think about this basic solution (any advice?):

AutoIt         
HotKeySet("{ESC}", "ExitProgram") Local $delay Local $ret Local $status Local $next, $nday, $nhour, $nmin, $nsec While 1     $ret = RunWait("s:\php\php.exe -f script.php", "s:\php\")     $status = "Last run: " & @HOUR & ":" & @MIN & ":" & @SEC & "     Return: " & $ret     If ($ret=0) Then   ; if no error in scripting, adding next run info to status         $delay = Random(3*1000, 6*1000, 1)   ; delay to next run             $next  = @HOUR*60*60 + @MIN*60 + @SEC + Round($delay/1000)   ; calculating next run in HH:MM:SS format             $nday  = Floor($next/86400)             $nhour = Floor($next/3600) - ($nday*24)             $nmin  = Floor($next/60) - ($nday*1440) - ($nhour*60)             $nsec  = Mod($next, 60)             ;$nhour = Floor($next/3600);             ;$nmin = Floor(Mod(($next/60),60));             ;$nsec = Mod($next,60);         $status = $status & "    Next run: " & StringFormat("%02d",$nhour) & ":" & StringFormat("%02d",$nmin) & ":" & StringFormat("%02d",$nsec)     EndIf     ToolTip($status, 0, 0)   ; displaying status info     If ($ret<>0) Then   ; if error in scripting, end program         MsgBox(0, "Warning", "Return code: " & $ret)         Exit     EndIf     Sleep($delay)   ; waiting for next run WEnd Func ExitProgram()   ; to terminating the program manually     Exit EndFunc


#5 hannes08

hannes08

    my oh my

  • Active Members
  • PipPipPipPipPipPip
  • 930 posts

Posted 25 April 2012 - 12:47 PM

Hello pantho,

you can use _DateAdd() to calculate the new execution time, without having to use the calculations and StringFormat()s you're using, though it's a good lesson :)
Having a Tooltip pop up every 3 - 6 seconds may be annoying ;)
Regards,Hannes
Spoiler

#6 pantho

pantho

    Seeker

  • New Members
  • 3 posts

Posted 25 April 2012 - 05:15 PM

Thanks for the tip ;-)
ToolTip is always visible in the corner, so there is no flickering
Here is the simplified version, any suggestion?

#include <Date.au3> Local $delay, $ret, $status While 1     $ret = RunWait("s:\php\php.exe -f script.php", "s:\php\")     $status = "Last run: " & StringRight(_NowCalc(), 8) & "  Return: " & $ret     If ($ret=0) Then   ; if no error in scripting, adding next run info to status         $delay = Random(3*1000, 6*1000, 1)         $status = $status & "    Next run: " & StringRight(_DateAdd('s', Round($delay/1000), _NowCalc()), 8)     EndIf     ToolTip($status, 0, 0)     If ($ret<>0) Then   ; if error in scripting, end program         MsgBox(0, "Warning", "Return code: " & $ret)         Exit     EndIf     Sleep($delay) WEnd





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users