20

I have a PHP script that checks my database's code for validity. How can I have this run everyday at a certain time so then I can just have it run on autopilot.

Strawberry
  • 66,024
  • 56
  • 149
  • 197

8 Answers8

20

What you want is called a cron job and is already covered here:

PHP: running scheduled jobs (cron jobs)

Community
  • 1
  • 1
zsalzbank
  • 9,685
  • 1
  • 26
  • 39
8

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:

wget http://yoursite.com/yourfile.php

which http://yoursite.com/yourfile.php should point to your desired function. You can also set repetition time interval over there.

This way yourfile.php is called in specified intervals.

VSB
  • 9,825
  • 16
  • 72
  • 145
3

CronJobs feature are often disabled on most free or cheap Linux hosting. If you could use cron you could use that.

Alternatives:

  • Use services like : http://www.setcronjob.com/ (many exist, just search on google) , to schedule your task for free(1x per hour).
  • If you need a little bit more juice you should look into google app engine cron. In the cron you just do a simple asynchronous request to call your page.
sqlchild
  • 8,754
  • 28
  • 105
  • 167
Alfred
  • 60,935
  • 33
  • 147
  • 186
1

There's a cli interpreter called php. Run your script through that as a cron job.

moinudin
  • 134,091
  • 45
  • 190
  • 216
0

May it will helps you.

You can schedule a task in Windows - control panel->administrative tools is where you find task scheduler.

run a php automatically after every hour

Thanks

Community
  • 1
  • 1
Vishal P Gothi
  • 987
  • 5
  • 15
0

If you are a linux/unix user, i recommend you use CRON .

guiman
  • 1,334
  • 8
  • 13
-1

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.

user2267379
  • 1,067
  • 2
  • 10
  • 20
-1

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 http://www.onlinecronjobs.com/

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.

Oliver A.
  • 2,870
  • 2
  • 19
  • 21
  • Windows Scheduler sucks. Its not reliable at all and does not run at the exact same time requested. – M H Jan 22 '18 at 17:43