How can I run a PHP script every few seconds in Ubuntu Server? (bonus: How can I run random within the cron script, e.g. every 3 seconds + random(3 seconds) )

  • 1
    I'd recommend that you first evaluate whether you actually need such short intervals. There's a reason they are discouraged, after all. – user98085 Aug 19 '13 at 21:40
  • What you are asking to do appears like it's a bad idea - in order to satisfy us that you know what you are doing, could you please give some more information about why you want to do this? What is your application? – thomasrutter Jun 17 '14 at 1:14

cron only runs at intervals of one minute or longer. If you really need, you could create a script of some sort that repeats whatever needs doing in a loop and sleeps for 3 seconds between iterations. But There's likely a better means to whatever ends you're actually trying to achieve.

  • you mean a minimum – Max Aug 19 '13 at 21:32
  • How would such a script look? – Max Aug 19 '13 at 21:38
  • Something along the lines of while(true){do_something();sleep(3);}. – Kevin Aug 19 '13 at 21:41
  • Which would work, but again OP, this is probably a bad idea - we need to know more about what your application/goal is. – thomasrutter Jun 17 '14 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.