I recently designed a website for a client which inluded access to an MLS Data Feed (IDX/XML)—a service provided for members of the Realtors Association of Maui. One the items on her wish list was an early‑morning email summarizing the previous day's new MLS listings.
cron is commonly used to automate system maintenance or administration, you can utilize
cron to send an email with information from your site.
Cron is a scheduling daemon available on Linux and other Unix variants that executes commands at specified dates and times according to instructions in a set of files called "crontabs." A system‑wide crontab file is usually stored in the /etc directory, and each users crontab file in the /var/spool/cron directory.
Creating Your Crontab With Plesk
Most web hosting providers allow access to
cron through an easy‑to‑use web interface. Mine is Plesk (version 9.5.4). To add a
cron job in Plesk:
- Log in to Plesk.
- Select the domain you wish to manage, and choose Scheduled Tasks from the Additional Tools group.
- Select the system user account and click Schedule New Task.
- Specify when to run your command, and which command to run.
For example, if you want to run your php script daily at 7:00am and have the information (new listings) sent to you via email, specifiy the following in the input boxes:
Note: If you are running PHP‑CGI (not as an Apache module), you may need to suppress HTTP header output by adding the Quiet‑mode switch to the command:
By default, the server will send output (or error messages) from the
cron job to the email address you specified when you set up the domain. You can change this email address in 'Preferences.'
The PHP Script
Potential PHP Gotchas
I have a 'library' of common include files that reside in a directory outside the domains on my server:
A list of directories where the
file_get_contents() functions look for files is specified in each domain's vhost.conf file.
Interestingly, these directives are ignored when executing a PHP script through
cron, and I received the following email message when I tested the