3.5. Setting Up the Mailing List

The project scripts in this chapter aren't meant to be run by a user visiting a web page, but rather periodically scheduled and executed automatically by the system. The digest.php script should run once a day to send the daily digest message, probably sometime late at night or during early morning. The best way to schedule individual.php depends on the membership size and the amount of messages your list will be receiving. Exactly how scheduling is accomplished depends on which operating system is installed on the server.

On servers running a unix-variant operating system, you'll be adding entries to a crontab file to schedule their runs and the cron daemon will execute them when it's time. To add entries to your crontab file, call crontab -e from the command line.

Each entry in the crontab file is made up of a series of fields separated by a space. Normally there are seven fields per entry, and each entry is on its own line. An asterisk (*) may be used in any field with no specified value and some versions of cron allow you to specify multiple values for a field by separating them with a comma.

Table 3-2 shows the expected fields.

Table 3-2. crontab File Fields
FieldDescription
MinuteWhat minute (0 through 59) the command will run
HourHour of the day in 24-hour format (0 through 23 with 0 as midnight)
DateDay of the month (0 through 31)
MonthMonth, may either be numeric (0 through 12) or textual ( January through December)
DayDay of the week, may either ...

Get PHP and MySQL®: Create-Modify-Reuse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.