This question already has an answer here:
PHP: running scheduled jobs (cron jobs)
What you want is called a cron job and is already covered here:
If you are using cPanel on your host, you can go to Advanced –> cron jobs.
Then inside there you can set a cron job command like this:
http://yoursite.com/yourfile.php should point to your desired function.
You can also set repetition time interval over there.
yourfile.php is called in specified intervals.
CronJobs feature are often disabled on most free or cheap Linux hosting. If you could use cron you could use that.
There’s a cli interpreter called
php. Run your script through that as a cron job.
If you are a linux/unix user, i recommend you use CRON .
May it will helps you.
You can schedule a task in Windows – control panel->administrative tools is where you find task scheduler.
If you have your own server you can run a cronjob(unix/linux) or a scheduled task(windows).
If your app/site is hosted on a shared host that does not offer cronjobs you an use a sevice like
I have not tested this one but If you google a bit(fee conjobs) you will find plenty of those.
They will call a certain a url accoding to a fixed schedule. Most of those sevices have a fixed set of ip addeses so you can pevent the scipt from being called by anyone else.
You can easily use your database to save the last execution of the script.
Each execution of a certain page you run a script that does the following :
Check if more than 8 hours (example)
Checks in the database if the script has already been executed
If executed: does nothing.
If not executed: starts and updates the date last execution in database.