This little script is handy to have in one's tool box in the event that cron or other triggering methods are not available. Once executed in the browser, it will run in the background indefinitely and loop through whatever desired script every 15 minutes.

It works well, HOWEVER... the only way I can halt the script is to restart the server. Does anyone have a better idea how to terminate the script if or when so desired???


<?php

ignore_user_abort(TRUE); // run script in background
set_time_limit(0); // run script forever
$interval=60*1; // do every 1 minutes...

do{
  // add the script that has to be run every 15 minutes here



  // ...
  sleep($interval); // wait 15 minutes
} while(true);


?>

    What your basically doing is creating a daemon

    Seems odd you access to reboot the server but not to cron. Anyway you can always issue a kill command once you know the scripts pid.

    Create daemons in PHP

      Is there any way I can kill it from the browser? Or by running another script from the browser?

        you can call kill with exec() from any php script, using start\stop functions in the url i linked to is a better idea.

          a year later

          I have never seen a satisfactory solution to this issue. Other than restarting the server, I have no way to kill this script. DOES ANYONE HAVE A BETTER SOLUTION????

            if you look at the code for the daemon above it has start\stop functions, no need to restart the server.

              well if you want help with that you are going to have to provide more information.

                Write a Reply...