0

I have a block of code and want to run it after certain time intervals, say after every 3 seconds. If I get required result it should die otherwise another request will be sent after 3 seconds. Any idea to do it with php.

Thanks in advance for any help

3
  • If you get more than 1 hit every 3 seconds, you could do it when a visitor hits your site, but this is very dodgy. You really do need to use cron. Commented Jun 5, 2012 at 10:08
  • but i have to pass some parameters to the function according to users request. Commented Jun 5, 2012 at 10:10
  • Any reason you dont wanna use cron? Only alternative is to have your users poll the server every 3 seconds via javascript and keep a check on last update but that would involve wasted resources. Commented Jun 5, 2012 at 10:12

2 Answers 2

4

You can sleep in a loop:

while (true) {
    $result = doSomething;
    if (resultIsGood) {
        break;
    }
    sleep(3);
}

If you don't want to keep the browser waiting, you can look up ignore_user_abort() solutions on Google.

Sign up to request clarification or add additional context in comments.

Comments

1

If what you want to execute MySQL queries (and nothing else), maybe using the MySQL event scheduler could fit your need:
http://dev.mysql.md/doc/refman/5.5/en/events-overview.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.