0

I run a php trading script every 20 seconds with AJAX from a web app. 20 seconds because its time execution differs from 6 to 18 seconds. I can't find a reliable way to improve this by running the script on the server side, and restart it after he finished last execution (as the more the script runs, the more he wins). I also want to be able to play/pause its execution from the web app ?

What would be the best way, which could run for weeks without being timeouted like a PHP do-while or a JS setInterval ?

Thanks for your help

Ben
  • 43
  • 6
  • Have you considered running the PHP script via a cron job? – b2238488 May 23 '15 at 11:57
  • Yes i had, but I will have to specify a time interval, i would prefer to re-run it right after it finished, unless there is a way with cron ? – Ben May 23 '15 at 12:01
  • You can make the cron execute the script every 5 seconds, and have the script check if there's already a script running, and it should only continue executing if there isn't already a script running. – b2238488 May 23 '15 at 12:08
  • user b2238488 is right. @Ben take a look at "Run cron job only if it isn't already running": http://stackoverflow.com/questions/2366693/run-cron-job-only-if-it-isnt-already-running – Jose Mato May 23 '15 at 13:31
  • I just rode that cron jobs have a 60 seconds granularity, where i need to run each ~12seconds ... – Ben May 24 '15 at 13:47

0 Answers0