Setting up PHP cronjobs (recurring tasks) for Joomla! extensions on Linux

Setting up PHP cronjobs (recurring tasks) for Joomla! extensions on Linux

With Matukio 4.3 we introduced some new time-dependent features, like automatic cancellation or confirmation of events X days before the start or automatic invoices X days after it. For these recurring tasks with PHP you need cronjobs. Cronjobs just execute a script or programm in a fixed rythm, in our case the Matukio cronjobs should be executed only once a day, but you can also set cronjobs to run every X minute or just once every week.

Please note: Windows offers something similar with Windows Task Scheduler, but in this post we are going to focus on Linux systems.

Depending on your environment there are different ways to setup cronjobs. In Joomla! installations cronjobs are normally stored in the /cli folder and they are mostly normal PHP files implementing the Joomla API.In this first part I am going to show you how to setup cronjobs in an Linux vServer / Rootserver environment. There are, depending on the extension, different approaches for that, we are going to focus on the direct PHP execution.Simple cronjob on a Linux server with direct PHP execution:Login into your server with SSH - you shouldn't execute PHP scripts as root, so maybe it's a good idea to create a new normal user or depending on directory permissions you would like to use the webserver user. After logging into the server type:crontab -eIf you want, you can export your favorite editor (if you haven't done so in for example your .bashrc already) with export EDITOR=nano first - if you aren't familiar with Linux command line editors, I suggest you try out Nano, which is a pretty easy and straight forward cli editor.After hitting enter the editor opens and you see your users crontab file - in this you create the recurring tasks.The syntax is pretty straight forward - your code begins after the comments (the lines with the # at the beginning).

Continue reading
Rate this blog entry:
2
17436 Hits
1 Comment