Cron

From OSClass

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 or administration. OSClass has a built-in functionality in case your system has no cron daemon, you could enable/disable it from the admin panel, general settings > cron. It's recommended to read more about CRON on the wikipedia. It's also recommended to use your system's CRON instead of the built-in functionality of OSClass, since you will get better results with the first one. We use this functionality to run a few jobs as sending email alerts or counting number of items per category.


Contents

CRON in OSClass

As said before, we need some 'jobs' to be done from time to time, from sending email alerts, to count number of items per category or allow plugins as sitemap perform other actions.

Files

CRON in OSClass is managed by 4 files, all of them are located on oc-includes/osclass folder: cron.php: Launcher of the rest of the files, this file will call the other files when needed (for example it will call cron.hourly.php once per hour) cron.hourly.php: This file will run once per hour cron.daily.php: This file will run once per day cron.weekly.php: This file will run once per week

We use cron.php to perform some calculations and consume less resources than calling each of the three files individually. In an ideal world, every server will have CRON enabled, and you will be able to set as many cronjobs as you want, but because we know that it's not always true, we offer this built-in functionality.


Configure CRON with OSClass

Configure the built-in functionality with OSClass

To use the built-in functionality you need to check the Auto-cron option on the admin panel, under general settings > cron.


Configure your system's CRON with OSClass

To use your system's CRON functionality you need to uncheck the Auto-cron option on the admin panel, under general settings > cron

Cron is only available on Unix system (Linux, Mac should have, but I never played with it). Most of the web servers out there are running a Linux distribution, it should be no problem at all. Windows systems have several alternatives to CRON which work in different ways. Usually, you need to SSH your server (access via SSH) and type on the command line/terminal this

crontab -e

You will enter your "cronjob list" on a terminal editor (usually vi, vim, nano or emacs). Then it depends on the editor to save, close, edit the file itself,...



Most hosting companies will not offer SSH access, and those who do it, some of them will not offer you the possibility to modify the CRON, but offer you a workaround via admin panel to do it. For example Dreamhost (under Goodies > Cron) offer you a "easy wizard" to run cronjobs, but limits you to one cronjob per user (via terminal/SSH you have no limits).


We can not provide you more information, since it highly depends on your hosting company/server.


A cron job need a time interval/time and a command to be executed, something like (really, more detailed on the wiki, I will not talk about the different time options)

* * * * * command params



In our case, we want to execute a php file , we need to have installed php-cli or php-cgi versions, which are the executables of PHP. (NOTE: Some server will only have the apache mod version of PHP, since performance is slower with the mod version and also have a few less features, It's strange that some server doesn't have it, but it could happen! ask your hosting company!). Well, we need to run the cli (command line interface or executable) version of PHP, we need to use the full path (your phpinfo could help you on this, or ask your hosting provider!) then, we need to pass as a parameter or argument the PHP file, use full path again (NOTE: Usually, shared server use the home directory to hold their users and websites, so your path will be /home/your_username/public_html, again, "public_html" is one of the most used folders, but it could be different, as website, yourdomain.com or anything. Also, if you own a private server, your web path is probably /var/www)


The whole cronjob should look like this

0 * * * * usr/local/php5/bin/php /home/your_username/public_html/oc-includes/osclass/cron.php

Set to run at every hour o'clock


So hosting providers, as Dreamhost, offer you a wizard, so you only need to input

/usr/local/php5/bin/php /home/your_username/public_html/oc-includes/osclass/cron.php

and select "Hourly"


Different setups

Best case scenario

You are able to run as many cronjobs as you want. In that case, set 3 cronjobs and execute the files oc-includes/osclass/cron.hourly.php, oc-includes/osclass/cron.daily.php and oc-includes/osclass/cron.weekly.php individually in your cronjob. Remember to uncheck General Settings > Cron > Auto-cron


Not so bad case escenario

You are able to run only one cronjob. In that case, execute oc-includes/osclass/cron.php in your cronjob Remember to uncheck General Settings > Cron > Auto-cron


You are not able to set any cronjob, don't want to or don't know how to

Check General Settings > Cron > Auto-cron and you're done.

Retrieved from "http://doc.osclass.org/Cron"