cronjob alternatives

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spec36
Forum Commoner
Posts: 28
Joined: Thu Nov 19, 2009 6:07 pm

cronjob alternatives

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: cronjob alternatives

Post 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:
  1. If the server restarts or anything happens, poof, and you have no way of knowing it
  2. 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.
spec36
Forum Commoner
Posts: 28
Joined: Thu Nov 19, 2009 6:07 pm

Re: cronjob alternatives

Post 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?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: cronjob alternatives

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: cronjob alternatives

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: cronjob alternatives

Post 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)?
Post Reply