1. Home
  2. Docs
  3. Mailster
  4. Cronjob Configuration
  5. Setting up cronjobs (in general)

Setting up cronjobs (in general)

What to do with your cron job URL / Setting up the actual cron job

There are different ways to set up a cron job. This depends entirely on the options available to you.

We will introduce you to the following methods:

  • cPanel – create a cron job via your webhoster
  • Root Server – create a cron job from the terminal
  • Web Provider – use a web cron job provider

cPanel Cron Job

This method applies only if your webhoster offers you a graphical administration interface (like cPanel) with cron job functionality.

Most interfaces look similar to the following screenshot:

You specify the frequency of the cron job’s execution by selecting the appropriate options. We recommend creating a cron job that runs every 5 minutes.

Do this by selecting the every year/month/day/week day/hour option and by selecting multiple minutes in a 5-minute interval (e.g. 0/5/10/15/20/25/30/35/40/45/50/55).

Many webhosters allow to only run local PHP scripts.
Thus, you create a PHP file named cronjob_mailster.php with the following content (here is an example with a dedicated cron job URL):

<?php
$htmlData = file_get_contents('https://example.com/index.php?option=com_mailster&controller=cron&task=all&key=secret&debug=true', 'r');
echo $htmlData;
exit;

Note: Mailster Business and Mailster Ultimate only allow dedicated cron jobs.
And here you will find a ready-made script file. Read more about that here.

You need to pay attention to what you insert as the command to run.

In the example given in the above screenshot, the first part, /usr/local/bin/php on our server, is the path to the PHP executable. This is a little different for each webhosting environment, but in most cases well documented in the hoster’s setup guide.
On some servers, it is enough to write php without an exact path.

The second part, the parameter -f, tells PHP to parse and run a file. It is optional and may be omitted.

The last part is the path to the file, relative to the root directory (that you can access). A good way to figure out this path is to login via a FTP client and navigate to the root. From this root, the whole path to the cronjob_mailster.php file has to be used for the cron job command.

Most cPanel offers a way to review the cron job result, either by logs or by emails. You should use this at first to see whether you get the desired output.

Terminal Cron Job

This method applies only if you have command-line access to your (Linux) server and the suitable user rights.

As the first step, create a file named cronjob_mailster.php, see the section above on what to put into the file.

Edit /etc/crontab with a text editor and add the following line:

* * * * * php /path/to/your/cronjob_mailster.php

This is the scheme of the crontab file:

Minutes [0-59]  
| Hours [0-23]
| | Days [1-31]
| | | Months [1-12]
| | | | Days of the Week [Numeric, 0-6]
| | | | |
* * * * * php /path/to/your/cronjob_mailster.php

The * means “every”. So our line makes the cron job run every minute (in every hour, day, month, year).

As this might generate too much unnecessary server load, we change it to “every 5 minutes”:

*/5 * * * * php /path/to/your/cronjob_mailster.php

For small, low-traffic lists (e.g., announcement mailing lists) you might find an “every hour” setting more suitable:

0 * * * * php /path/to/your/cronjob_mailster.php

Basically, every interval is possible. Many more examples on the crontab’s syntax can found on the web, e.g. on Wikipedia (see http://en.wikipedia.org/wiki/Cron).

An alternative to using a PHP executable to trigger the site is using other applications that act like a web browser. This has the advantage that you don’t have to work with PHP scripting file.

Here is an option of a cron job that is executed every 5 minutes using the command-line tool wget:

*/5 * * * * wget -O - -q "https://example.com/index.php?option=com_mailster&controller=cron&task=all&key=secret&debug=true" >/dev/null 2>&1

That’s the best option to not download/save anything while executing wget – otherwise, you would save the returned HTML on each cron job execution

Note that you have more options in terms of command-line programs to use (e.g. lynx or curl). You have to see what is available and working on your host.

Web Provider Cron Job

There are many web cron job providers out there. For example Easycron.com and Webcron.org.

They all enable you to set up a URL-based cron job relatively easily.

Here is an example based on Easycron’s user interface:

You need to enter the URL and define the frequency (here every 5 minutes).

Beware of the Caching

Some web hosts apply caching. That means your site is not always freshly generated when browsed. In those cases, the cron job may not work or only work sometimes.

We recommend speaking with your hoster to either deactivate the caching for the specific cron URL, or introduce a random/changing URL element to the cron URL. This requires, depending on the cron type, some technical skills.