set cron jobs with php script?

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
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

set cron jobs with php script?

Post by bwv2 »

Here's what I have:

A user submits a page using a form. The page takes the user input and places it in a MYSQL database. It also calculates a time 3 days in the future and writes it to the user's mysql row. The user leaves on his or her merry little way.

Here's what I want next, but don't know how:

As soon as that future time is reached, a php script will be executed. The contents of the executed script are irrelevant- it's how to get it to call the script at the right time without being prompted by a user calling a page that's causing me strife.

I have looked into cron jobs a little (I'm new to the concept). Could I write one cron job now that would last forever, and that would automatically run a script that checks the db for expired future dates? If so, how do I get the cron job to do this? And how do I write a cron job? (I do have admin access to the server).

I hope that makes sense. I'm a little lost.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yes, a cron job is what you're wanting.

Set it to run every minute. Have it execute a script that checks the database for users who's time expires during that minute. The script should do whatever is needed for those users. It should also mark them as being handled. This way you can also perform operations on other accounts that may have been missed by a previous run (or absence thereof.)

We've had several threads dealing with the syntax of cron. There are also lots of web sites that show the various parts of setting a cron job.
Post Reply