I may be a tad late to the game here but if you are using Linux or Mac this should work fine for your needs. --Terry Valladon $random_number = rand(); // I will let you worry about seeds and stuff, perhaps call your own make_random() function? print('Random number is '.$random_number."\n"); declare(ticks = 1); // Set ticks to one second pcntl_signal(SIGALRM, "signal_handler"); // Installs a signal handler for SIGALARM (works in linux/mac only I think) pcntl_alarm(1200); //trigger alarm in 20 min (60 seconds * 20 min = 1200 seconds) // This is just to keep the script running forever, I would HOPE you would have real code in here rather then just looping endlessly. for(;;) { sleep(1); } function signal_handler($signal) { global $random_number; switch($signal) { case SIGALRM: $random_number = rand(); // New random number, I will let you worry about seeds and stuff, perhaps call your own make_random() function? print('New random number is '.$random_number."\n"); pcntl_alarm(1200); //trigger alarm again in 20 min break; // Exit function and continue normal code execution. } }
T
Terry Valladon
@Terry Valladon
Posts
-
randomly generate a number every X minutes (php)