pantho Posted April 24, 2012 Share Posted April 24, 2012 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. Link to comment Share on other sites More sharing options...
MrMitchell Posted April 24, 2012 Share Posted April 24, 2012 (edited) 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:While...Wend loop ShellExecute() HotKeySet()and the section about creating custom functions.Post what you come up with along with questions if you have trouble.Edit: Go if you need help with Help File and just getting started... Edited April 24, 2012 by MrMitchell Link to comment Share on other sites More sharing options...
hannes08 Posted April 24, 2012 Share Posted April 24, 2012 I would suggest to use Run() or RunWait() to run the php scripts, as you'ss receieve the return code. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
pantho Posted April 25, 2012 Author Share Posted April 25, 2012 Thanks for help, what do you think about this basic solution (any advice?): 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 Link to comment Share on other sites More sharing options...
hannes08 Posted April 25, 2012 Share Posted April 25, 2012 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]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
pantho Posted April 25, 2012 Author Share Posted April 25, 2012 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now