Query on timer

Posted on 2012-08-14
Last Modified: 2012-08-30
If I have a script that runs a query and the query comes up empty, is there anyway to have the script automatically run again in a minute or two?  Like a sleep for a few minutes mode then run again?  Without using a CRON Job?
Question by:rgranlund
    LVL 65

    Expert Comment

    by:Jim Horn
    (1)  Set the form's Timer interval to # of seconds you want it to fire * 1000 (e.g. 3000 = 3 seconds)

    (2)  Set TimerOn property to True

    (3)  Write VGA code in the form's OnTimer event to run your query
    LVL 49

    Expert Comment

    by:Julian Hansen
    You are talking about a script running based on a request from a browser?

    If so then not really because the script runs, terminates and won't run again until it is triggered by a request to the server.

    You can probably rig something up to make the script pause by running a loop

    $x = time();
    while(time() - $x < 60) {
     set_time_limit(60); // so script does not time out

    But then browser will sit in a loading state until the above returns again.

    The other option (not sure if this will work for you) is to send the page back with a meta refresh or javascript refresh to get the page to call the script again.

    Alternatively use a javascript timer and call an AJAX function to re-run the script.
    LVL 65

    Expert Comment

    by:Jim Horn
    Disregard my previous comment.  For some reason I thought this was an Access question.
    LVL 107

    Accepted Solution

    Why not just use CRON?  Anything else would feel like a jury-rigged solution.

    But that said, here is a design pattern that will work (at least until something in one of the scripts fails).

    1. Write the script that runs the query.  Its browser output should be the number of seconds to wait before it is to be run again.

    2. Write the initiator script.  It starts the query script using CURL or file_get_contents().  With the response value, simply sleep() for that number of seconds, then loop back to start the query again.

    You will probably want to add set_time_limit() into the initiator loop to make it a truly long-running job.  You will also want to have some good error checking and logging in the query script, so that if it fails for any reason, the initiator script will get the response back and can notify you via text or email that there is trouble.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    This article describes some very basic things about SQL Server filegroups.
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    The viewer will learn how to count occurrences of each item in an array.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now