Forum Moderators: coopster
<?php
$interval=60; //minutes
set_time_limit(0);
while (true)
{
$now=time();
include("the_script.php");
sleep($interval*60-(time()-$now));
}
?> The include() function could become file_get_contents() using a full http:// path if you are worried about memory leaks in your script.
Stop the script by restarting apache, or build in a return value from your internal script which changes while (true) to while (false)
some hosts may block or not look kindly on php scipts that allow system commands and how do you make sure the script is always running?
id use cron to fire the script.
also some tips to avoid some gotchas (i used to write billing software for a very big telco)
1 cater for the null condition what happens if an update is empty
2 make sure updates cannot run more than once
3 have a mechanisiam to log what updates are run
4 have a mechanisaim to revert an update
5 log everything in detail
6 dump failed updates to another file so you can try to analyze the problem and reinject transactions later (this is part of 2)
7 audit the updates ie if 1000 updates are input are 1000 updates actually done - if its financial information check the totals tally
CRON and PUTTY
CRON (cron tables could be edited via the command line or using putty)
Using putty:
Enter IP address
Left nav click SSH to expend and click again SSH
Move "BLOFISH" to the top of list
Click “open”
Using PICO editor: (putty DEFAULT EDITOR)
Enter your UN, press enter
Enter your PW, press enter (don't be surprised in Linux fashion the PW typing is hidden!)
Type in: crontab –e (space between crontab and –e)
If there are any pre-existing “jobs” from the server admin move those down two lines
to comment your job use ###########
Go back to the top and enter your task
Here we use wget()
To use wget() you need to ensure that it is installed
Type in the PICO: wget –help press enter
If you get a bunch of information then you are OK
Type in the PICO:
1 */3 * * * wget [my_web...]
Ex: should run the first minute of every three hours (8 times a day)
Press enter
Last: Press ctrl and x to exit
You will be asked to type Y or N
Type your answer
Press enter
That’s it done!
FYI: bottom of PICO shows a list of commands
Each starting with “ ^ “ do not type the ^ it only means: Press CTRL :)
PHP script:
Needs to be shmod at: 755