Beginning with IProperty 3.0, you have the option to allow users to subscribe to automatic email updates for both Properties and Searches.

Cron Jobs Overview

Figure A: IProperty Cron
Figure A: IProperty Cron

The ‘Email Updates’ options are available to enable/disable in the IProperty Settings Panel, in the Properties and Advanced Search areas respectively. If both of these options are set to No, then the email updates will not function regardless of whether you create a cron job as detailed below.

What is Cron and how does IProperty use it?

Cron is simply a system-level utility found in most server software that allows users to schedule tasks. You can set cron to fire a given task on almost any schedule you desire – every second, minute, hour, day, or every third Sunday. In the IProperty use case, updating users to notify them of new search results or modifications to their saved property updates, we recommend at most to run the job once a day.

For the purpose of this discussion, we’ll assume that we’re going to run the job once a day, at 2am, and send both saved search updates and saved property updates.

To put it simply, all we’re going to do with cron is to request a page from your IProperty site. That page will then perform the queries, create the emails and send the updates for you. To prevent malicious users from simply requesting this page to tie up your server resources and annoy your users, you will pass in a hash of the $secret from your Joomla site as a Key. We hash the key as a precaution against a “man in the middle” attack, so that even if a hacker had access to the network traffic, he would not be able to get your site’s secret variable.

Let’s get started!

You will need to take a look at your Joomla configuration.php file, and copy the $secret variable (it will look something like this: tiEt58hN6LCbB0rk). We’re then going to create an MD5 hash of this value. You can generate an MD5 hash using a simple PHP script, or you can access an online MD5 generator like the one found here.

Simply plug in your site secret (without the single quotes!) and copy the resulting hash.

The format of the URL to request via the cron job is as follows:

html www.mysite.com/index.php?option=com_iproperty&view=property&format=eupdate&secret=YOUR_JOOMLA_CONFIG_FILE_SECRET&listing=true&search=true&limit=X

If both of these values are absent or set to false, then no updates will be sent.

Set X to the maximum number of listings to send in a search update. We recommend about 25. Any more than that and the email becomes awkward to read.

Set secret = your MD5-hashed secret.

In most cases, you will simply use the UNIX/LINUX utility WGET to request the page from your server. However, there are other alternatives, including using Lynx or cURL. These alternate approaches may be required depending on your host. Again, check with your hosting support for more information on the best way to request the URL via cron.

An example of how you’d set up your cron job using a command-line cron interface.

$ crontab -e

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

# heres the line we add to the cron script
0	2	*	*	*	WGET http://www.mysite.com/index.php?option=com_iproperty&view=property&format=eupdate&secret=e94e22c47fff6afc9a4f49025162d982&listing=true&search=true&limit=25’
Tags: iproperty cron