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")
开发者_StackOverflowWhat else can I use to do this? (Sql seems like it might work, but I've searched and can't tell for sure)
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".
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.
You can use crontables on unix system to run periodical updates.
Use Cron:
crontab -e
Then you edit the file like in vim or vi.
http://blog.linuxvin.com/wp-content/uploads/2010/07/crontab-syntax.gif
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
精彩评论