0

Basically what I need to do is to update a database every X days/hours/minutes/seconds (to be set). How can I let a PHP page execute regularly?

Xriuk
  • 382
  • 2
  • 7
  • 26

4 Answers4

2

Use a CRON job.

If you are using a hosting service with cpanel there is an option to set and it can be quite straightforward.

Otherwise there are plenty of CRON tutorials on the interwebs.

Be sure that the permissions on your script are set correctly for it to be executed.

Steve
  • 1,371
  • 1
  • 16
  • 38
1

This feature is not provided by php, but by another program depending on your operating system (crontab in unix, scheduled tasks in windows).

Calimero
  • 4,238
  • 1
  • 23
  • 34
1

your choices are cron (as everyone is mentioned) in unix, task scheduler in windows, or a header in your php to check a file to see if whatever you need to happen has been processed in the last X minutes / hours / days

but the php-option is a terrible idea if cron/task scheduler is at all possible.

virmaior
  • 424
  • 4
  • 14
-1

You can have for instance an HTML page reloaded every 15 seconds like this:

<META HTTP-EQUIV="refresh" CONTENT="15">

but is certainly wise to do this via cron or corresponding system tools to schedule repeated a programs.

anw
  • 162
  • 2
  • 1
    This will only work if the page is open in a browser. – Steve Dec 21 '13 at 22:32
  • Of course - the question was "How can I let a PHP page ..." – anw Dec 21 '13 at 22:42
  • True, but a bit of common sense makes the real intent of the question clear - he meant script, not page. "update a database every X days/hours/minutes/seconds" – Steve Dec 22 '13 at 21:10