Working with Cron?

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
Caped Knight
Forum Commoner
Posts: 33
Joined: Wed Jan 01, 2003 6:20 pm
Location: Somewhere...out there...

Working with Cron?

Post by Caped Knight »

I have a website in which I need to update the database once every hour. I only have an obscure idea of how. Can someone point me to a tutorial or something? I'm not very good with Unix. I just need to run once script every hour.

Thanks.
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Add this to your crontab:

Code: Select all

01 * * * * /path/to/php /path/to/a/php/file/which/updates/your/database.php
EDIT: Too many stars :oops:
Last edited by qartis on Wed Aug 13, 2003 3:06 am, edited 1 time in total.
Caped Knight
Forum Commoner
Posts: 33
Joined: Wed Jan 01, 2003 6:20 pm
Location: Somewhere...out there...

Post by Caped Knight »

Thanks, qartis. Can you tell me what it all means? Just so I understand in case I'm using different timing in the future.
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Whoops, I read "not very good" as "very good" :)

To edit your crontab, at a sh or bash prompt, type 'crontab -e' to edit your crontab, and then add that line into it. Then press the [ESC] key, and type "ZZ" [Enter] to save your crontab and quit vi.
Caped Knight
Forum Commoner
Posts: 33
Joined: Wed Jan 01, 2003 6:20 pm
Location: Somewhere...out there...

Post by Caped Knight »

Lol. Thanks again.
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Oh, and the meanings? Well, a crontab uses a simple structure. The 01 * * * * represents this:

A minute, expressed as a number from 0 through 59.
An hour, expressed as a number from 0 through 23.
A day of the month, expressed as a number from 1 through 31.
A month of the year, expressed as a number from 1 through 12.
A day of the week, expressed as a number from 0 through 6 (with 0 standing for Sunday).

And an asterisk means every one. So, 01 * * * * means "every month, every day of the week, every hour, one minute out of the hour (the first one).

To get a cron job to run at 3:30 PM every day, you would use 30 15 * * *.

Argument number six is the command to run, and everything after it (including spaces) is included in the command.

My first snippet (condensed) would run `/path/to/php /path/to/file/php` as if it were typed at a prompt.
Post Reply