views:

70

answers:

4

I need my site to occasionally read a file in order to update itself. (Daily or weekly if possible)

Is php capable of this alone? (From what I've seen the answer is "no")

What else can I use to do this? (Sql seems like it might work, but I've searched and can't tell for sure)

A: 

You can use crontables on unix system to run periodical updates.

Aif
+3  A: 

You could use a cronjob that executes your php-script at a given interval (eg every day at 12pm).

In case you cannot use real cronjobs: there are also some sites that offer free "cronjobs" - you give them a URL and they visit it at the time you tell them to. Just google for "free cronjobs".

Nils Riedemann
There is a second alternative to real cronjobs - simulated cronjobs. Each time a user visits a site they themselves can be the trigger for the 'cron job'. A table holds cron information (frequency to run, command to run), and if the current time minus last time the script was run exceeds the interval execute the command. Of course the down side to this is that if no-one visits the site, the 'cron job' will not run.
Seidr
I actually already thought of updating when the page loads. I turned the idea down because I'm looking for consistency rather than convenience.
A: 

Use Cron:

crontab -e

Then you edit the file like in vim or vi.

This would execute everyday:

0 0 0 0 0-6 /absolute/path/to/the/executable

If you want to make your php script executable use the ol' she-bang. Add:

#!/usr/bin/php

or whatever the path is to your php interpreter to the first line of your PHP file and then do:

chmod a+x yourfile.php
akellehe
A: 

Cronjobs are the obvious answer (for linux based servers). However for people who don't have the ability / permissions to do this on their paticular environment.

The other option is to build a simulated cron. Which basically executes a script every time the site / page is loaded. This could then check the current time / date and decide whether it needs to perform further operations, in your case the update operation.

David Cooke