Page 1 of 1
cronjob alternatives
Posted: Thu Sep 16, 2010 5:23 pm
by spec36
Hi all,
I do not have access on my web host to setup a cron job. Does anyone have any ideas how I could get around this? I want to be able to run a php script every hour or so. I guess I could write a script that once run would keep connecting to a web address specific to a desired time interval. Any recommendations on this? Any PHP functions that could help me with this?
Thanks,'s
Re: cronjob alternatives
Posted: Thu Sep 16, 2010 6:00 pm
by Jonah Bron
If it "no more than an hour" is necessary, you can do what's called a "poor man's cron". You setup a data storage format (text file, etc.), and every time a user visits, it checks the data. If it's older than (in your case) an hour, make it run the script, and update the data with the current time. If not, do nothing.
There are a couple of big problems with your other solution:
- If the server restarts or anything happens, poof, and you have no way of knowing it
- I don't know, but sleep()ing too long might make the script go past it's max execution time setting.
There's only one last solution. Setup a cron/windows scheduler on your computer to execute the remote file.
Re: cronjob alternatives
Posted: Thu Sep 16, 2010 6:12 pm
by spec36
Sounds good. Thanks for the info. I think I will with the Task scheduler on Windows, but how do I direct it to the php script? Any idea?
Re: cronjob alternatives
Posted: Thu Sep 16, 2010 6:34 pm
by Jonah Bron
It looks like Windows doesn't have anything for this built in, so you'll have to install WGET for widows, or some other equivalent.
http://pages.interlog.com/~tcharron/wgetwin.html
Re: cronjob alternatives
Posted: Thu Sep 16, 2010 7:12 pm
by John Cartwright
If you want to run a local PHP script on your server, then a simply command along the lines of
[text] C:\path\to\php.exe "C:\Inetpub\wwwroot\mycron.php"[/text]
Should do the trick.
If you want to hit a remote website, then wget is probably your best bet.
Re: cronjob alternatives
Posted: Thu Sep 16, 2010 7:26 pm
by Jonah Bron
spec36 wrote:I do not have access on my web host to setup a cron job...
Sounds like he's implying a remote file. Unless the script could just be run on his computer (unlikely)?