Periodic function for web app

lomn75

Purple Ace
Joined
Jun 26, 2000
Messages
6,613
I've got a web site I'm working on (mostly PHP) and I need to run a function periodically; for instance, every day at 2AM or the like. Any recommendations on how to set this up (for example, is there a way to run a PHP file as a cron job, and if so, how) ?

As a follow-on, is there a way to prevent Joe Browser from calling this function? For instance, can cron successfully invoke a PHP file outside of htdocs -- again, if so, how?

Thanks,
Stephen
 
Do you have access to the server in a way that will allow you to setup a cron job?
If so you should be able to run a php script as a cronjob. You'll have to, of course, setup the cronjob and unfortunately I don’t have a lot of experience under *ix which I'm assuming you're using. However a few searches in google should get you on track as this use of cron if highly publicized.

Most of what I've read shows that you launch it with the php interpreter and then the script.
cron should be able to run scripts outside of your specified documentroot (htdocs). (again I'm not terribly familiar with *nix cron - you may have to supply user credentials to it.) However, I did find a descriptive site here http://www.4webhelp.net/tutorials/misc/cron.php.
Here is another one that seems promising - http://www.phpfreaks.com/tutorials/28/0.php

If you do not have access to the interpreter directly you should be able to run it with 'wget' (again just what I've read) and then call the php page. Of course this means that you would have to have it accessible over the web, but you should be able to bury it and practice "security through obscurity (TM.)" by not publicizing where it lives.

sorry I couldn’t be exact for your question. Knowing the platform & situation would help a bit.
Thanks,
 
Great! Link #2 was exactly what I was looking for. I didn't go into platform, etc, as I'm wanting to make sure I can pull it off cross-platform (though I've got a cron version for WinNT)
 
lomn75 said:
Great! Link #2 was exactly what I was looking for. I didn't go into platform, etc, as I'm wanting to make sure I can pull it off cross-platform (though I've got a cron version for WinNT)

I'm glad I could help. I imagine that the syntax for the cronjob could be diffrerent cross-platform, but I'm sure the general theme would be the same.

The thing about technology is that it's supposed to work for you to help you get more done, and not to make you work more to use the technology. ;)

Cheers!
 
Back
Top