4 minutes reading time (753 words)

Don’t You Forget About Me - How CRON changed my working week

2024--JCM-March-CRO_20240316-170839_1

As a young IT manager, sometime at the end of the last century, I came across a term that interested me a lot. It was “set it, and forget it”. Sounds a bit haphazard, doesn’t it? Apparently it was less to do with software than rotisserie chicken cooking. You'll find it on Google. Why would I want to forget something important? Well, semantics aside, the principle meant that I could go off and do other things rather than waiting to make sure my backups had run. 

Wind forward a few years, and besides backups, I had extensions and plugin updates on several dozen websites, and my day could have been filled with watching progress bars on-screen as I waited for a process to finish. 

How does CRON help when using Joomla?

For one thing, in Joomla 5, I can use the Task Scheduler. It has a whole range of functions though at least 50% of them are related to Akeeba Backup or Admin Tools in my case. I think using tasks from within Joomla also relies on some server config as my own attempt to use the Admin Tools Cache clean-up caused some errors. I’m not sure how toggling a site offline at regular intervals would be useful, but please let me know if there is a use-case for this.

Thankfully using cPanel hosting, CRON meant I could do my own setting and forgetting. There are 2 methods I deploy, one is to run a script by calling PHP as the command. The other is to call a page URL using cURL.

PHP scripts are called where a function is written using Joomla’s CLI application, much like typing a command into Terminal (on a Mac) or PuTTY on Windows. For a longer explanation about CLI, take a look at Brendan Hedges’ article from 2022.

Other Joomla components use a call to a URL and more than likely include a Private Key to prevent an action being triggered by accident, such as when a web bot hits your site, maybe for crawling. 

Real world examples

I run a music listing website (there's a link in my biog) that constantly needs updating with new information as gigs are announced. The basic admin area allows me to add data via a form, however, I’ve sometimes added 80 gigs in a day and that once meant a lot of copy / paste and hitting the save button. Thankfully I’ve developed a process for adding data via CSV and this can very quickly be updated and uploaded via FTP to the webserver. I have set CRON to run 4 times a day so that any new information is swiftly added into the site. ie 9am, 1pm, 7pm and 11pm. CRON lets me set this odd arrangement of intervals by choosing the hours and setting a minute in that hour, ie 0 = on the hour.

You can see in this redacted screenshot how the tasks are run. There is usually more than enough information in a component’s documentation to show you how to add the task into CRON and there are some handy shortcut settings that mean if you want to do a backup at midnight every day, the dropdown will set that for you. 

Besides posting new content, I also need to make sure that I’m not serving stale content, and that visitors are seeing the latest information. Running a cache cleanup command means I don’t have to go back into the dashboard and either click my shortcut button or a few more clicks again to clear the cache. This might seem lazy but I feel that this is my own contribution to working smarter, not harder (as the saying goes)


What else can Joomla do with CRON?

I’ve seen suggestions for updating components automatically, though some of the ones I use don’t easily update that way. Whichever way you update you’d still want to test the site to make sure it works afterwards.

There are tasks where uploads or emails may need to be processed, ie for helpdesk ticket management. In e-commerce, you may want to send a reminder to customers if they have abandoned a basket before making a purchase. In many cases, this will have been configured by the component developers. 

However you manage your Joomla site, if a task is repetitive and painful to keep doing, take a look at the documentation or even ask the question of the developers about how automation could free you up to do other more useful tasks.

 

0
Less than 10 mins to change the design of the logi...
CSS is evolving, evolve your code with this simple...
 

Comments

Already Registered? Login Here
No comments made yet. Be the first to submit a comment

By accepting you will be accessing a service provided by a third-party external to https://magazine.joomla.org/