1 - Introduction
This article will help you setup the automatic transfer of media files to your CDN using CRON.
CRON is a time-based job scheduler in Unix-like computer operating systems. CRON enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. It is commonly used to automate system maintenance. Read more on Wikipedia
2 - Quick Start
Using PHP
Running this maintenance using PHP is by far the most efficient method to process your media files. The required command in Linux is as follows
/usr/local/bin/php -q /path/to/joomla/administrator/components/com_joommedia/cli.php cdn
- Replace /usr/local/bin/php with the path to PHP on your server
- Replace /path/to/joomla with the path to Joomla on your server
Using WGET
The required command in Linux is as follows
/usr/local/bin/wget -q http://www.yourdomain.com/index.php?option=com_joommedia&task=maintenance.cdn&format=raw&token=xxxxxxxxxxxxx
- Replace /usr/local/bin/wget with the path to PHP on your server
- Replace www.yourdomain.com with the domain of your Joomla site
- Replace token=xxxxxxxxxxxxx with the Secret from your Joomla Global Configuration.
3 - What does this process do?
Understanding what happens when this process runs is important.
- joommedia will load your CDN plugin, and check that your plugin parameters are correct. This includes checking the API credentials you have supplied are valid. If the credentials are incorrect or joommedia can not access your CDN, then it will exit the process.
- joommedia will look for any media files that are stored on your local server.
- For each media item in the list, joommedia will skip any items that still has queued processes. This will prevent the transfer of any media which has not been fully processed yet.
- For each media item, joommedia will load all the files associated with that item and transfer them to your CDN. It will check that the filesize on your local server matches the filesize on your CDN.
- If all file transfers are successful for a single media item, then joommedia will update your database so that the media item is listed as a CDN entry, instead of a local media item.
- Once this is complete, and there are no errors, joommedia will delete all the media items associated with this item on your local server.
4 - Using CRON
There are numerous extensive guides on the internet which explain how to use CRON.
CRON in Linux
To execute the joommedia conversion script every 30 minutes you should create a Cron task like the one listed below.
*/30 * * * * /usr/local/bin/php -q /path/to/joomla/administrator/components/com_joommedia/cli.php cdn
You might want to schedule your processing to run at quiet times on your server (for example, at night).
CRON in cPanel
CRON in Plesk
Scheduling tasks in Windows servers
Windows doesn't support CRON, but has it's own Task Scheduler. Windows users will need to use this to setup scheduled maintenance.