CRON: https://www.freebsd.org/cgi/man.cgi?query=cron&sektion=8&apropos=0&manpath=FreeBSD+12.0-RELEASE+and+Ports
CRONTAB: https://www.freebsd.org/cgi/man.cgi?query=crontab&sektion=5&apropos=0&manpath=FreeBSD+12.0-RELEASE+and+Ports
You might be a windows user, in which case perhaps you've heard of "Scheduled Tasks"? Scheduled Tasks was probably modeled on Cron(8)
.
Cron(8)
runs continually on most Unix-like systems; it wakes up every minute and reads the user and root crontab files, and if there's anything in them scheduled to run at that minute, it attempts to run the script using its shell.
So if you don't know much about operating in a shell environment, you've got some catching up to do.
Here's an example crontab file:
#FOO.com CRON SYSTEM
# Minute Hour Day Month Weekday Command
*/6 * * * * /www/www.foo.com/cron/frequent.php > /dev/null 2>&1
59 * * * * /www/www.foo.com/cron/hourly.php > /dev/null 2>&1
02 0 * * * /www/www.foo.com/cron/daily.php
00 0 * * * /www/www.foo.com/tools/wlizer
Every six minutes the system runs frequent.php
. At 59 minutes after every hour it runs hourly.php
. At midnight it runs wlizer
and two minutes later runs daily.php
.
Now, these PHP files are meant to be run in the shell/CLI. Each starts with a shebang line:
#!/usr/local/bin/php -q
<?php
do_stuff();
Note that PHP isn't always at /usr/local/bin/php
on every system/server, so some installations would have a different interpreter line there, while others might attempt to use env
to have the system locate PHP itself for portability's sake:
#!/usr/bin/env php
<?php
do_stuff();
Note that as Laserlight points out, cron(8)
doesn't have anything to do with the web. There's no need to generate HTML unless you intend to view the output from a job in a browser at a later time.
However, cron(8)
does by default send an email to the user who's crontab it being run, unless specifically instructed not to. In the example crontab above, I've redirected both stdout
and stderr
to /dev/null
(a blackhole, basically) for frequent.php and hourly.php, but I WILL get an email for the daily.php job.