Page 1 of 1

Running scripts without web page request?

Posted: Sat Mar 11, 2006 9:33 am
by B2Ben
OK... I'm not sure if this is possible or not, but here goes...

I'm building a mailing list system for a local movie theatre chain. They want to send showtimes to their subscribers every week.

They'll probably want to revise the e-mails before they go out, so maybe I won't even need this question answered, but I'm still curious.

Is there any way to run a PHP script, and have it triggered by the date/time? NOT by a web page request? For example, the movie showtimes e-mail could be automatically generated and sent at say 3:00am every Monday. Can that be done? I imagine it would take more than just PHP to do that.

If anyone knows, let me know what you think.

Posted: Sat Mar 11, 2006 9:36 am
by timvw
All you need is something to invoke php at regular times/intervals.. Most *nix environments use crontab for that. Under windows you'd probably use the task scheduler... If i'm not mistaken there is a win32 port of crontab for windows now too... Just search this forum (or the web) for cron(tab) and you'll find a lot of good links ;)

Posted: Sat Mar 11, 2006 9:36 am
by feyd
store the send timestamp in a database or flatfile if necessary and use a cron script (called each minute or so)

Posted: Sat Mar 11, 2006 9:40 am
by B2Ben
How do I find out if/how my web host handles crontab and how to use it?

Posted: Sat Mar 11, 2006 9:47 am
by s.dot
most webhosts provide a front end for managing your account (like cPanel)
look for an icon or a link to CRON/CRONTAB in their controlpanel

Posted: Sat Mar 11, 2006 9:48 am
by Roja
B2Ben wrote:How do I find out if/how my web host handles crontab and how to use it?
Ask them.

Posted: Sat Mar 11, 2006 10:10 am
by NightFox
I think cPanel says something like "Manage Cron Jobs"
If you don't want to wait for your web host to respond to your email, or pick up the phone, you can always try using your browser's "Find" feature (CTRL + F) and search "cron"

Posted: Sat Mar 11, 2006 10:20 am
by B2Ben
Unfortunately this particular host seems to run some other control panel... "ensim" I think, or something like that. I'll ask tech support and see what they say.

Posted: Sat Mar 11, 2006 10:28 am
by s.dot
just try ermm...

Code: Select all

if(exec('some crontab function')){ echo "yes Cron!"; } ELSE { "no cron.. poopsticks =["; }
although I have no clue what that function would be, sorry :P

Posted: Sat Mar 11, 2006 6:19 pm
by NightFox
scrotaye wrote:just try ermm...

Code: Select all

if(exec('some crontab function')){ echo "yes Cron!"; } ELSE { "no cron.. poopsticks =["; }
although I have no clue what that function would be, sorry :P
lololol wow, that's the *best* code i've ever seen! =P

Posted: Sat Mar 11, 2006 6:48 pm
by josh
If you have shell, just type:

Code: Select all

# crontab -e
to get to your crontab file, use google to find the right syntax to use in this file.