Request quote

How to create cron job for Elgg?

Posted on: April 10th, 2012 by Mohammed Aqeel 10 Comments

It is a common question we are getting from the elgg community,  to help people in setting up elgg cron jobs in their installation. You may not be aware that Elgg requires a cron to be run. But actually it needs. For those new comers here is an introduction to cron, its purpose, and how to set it up.

What is Cron / Cron job?

Cron is a unix utility that allows some tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix.  Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times. You can see such a file inside the elgg download package.

Why do I need Cron?

Configuring cron is an extremely important task in your Elgg website setup. Cron is essential for some modules like logrotate, garbage collector etc.. which are required t keep a log of your users activity on the site, remove orphan entries from the databases etc.. Some third party modules like anti spam tools also require cron to remove the previous banned IP’s from the database. With a properly set cron you can send your users birthday wishes, regular email alerts etc.. You can set a command or script to run at a specific time every day, week, etc. For example, you could set a cron job to delete temporary files every week to free up disk space.For the Team Webgalli site, we are using a daily cron job to optimize the DB Tables, Clean up the orphan DB data, Truncate unnecessary DB tables, Post a tweet daily from our latest blog, Clean up old cache and junk datas from disk etc…

How to set up Cron?

Actually it is very easy thing. There are multiple ways of setting up a cron. Here we will explain it on a cPanel based system. You can do it by

  1. login to your cPanel >
  2. Find the Cron Jobs button (usually it is under the advanced tab).
  3. Open the link.

Here you will able to see three options . 

1) Cron Email

Enter your email address here, so that the system will send you the result of the cron job once the cron runs. You can change this email anytime.  If you do not want an email to be sent for an individual cron job you can redirect the command’s output to /dev/null like this: mycommand >/dev/null 2>&1

2) Add new cron job

Here you will see a pull down called common settings. Select one of it (these can be every minute, every five minute, every day, every month etc..) Also note that some hosting providers wont provide the every minute or every five minute (small durations). Now in the command area enter the code as follows (click on the image for a bigger resolution)

/usr/bin/curl http://mysitename.com/cron/daily/

This will tell the system to call the page http://mysitename.com/cron/daily at the intervals you specified. The allowed intervals in Elgg are minute, fiveminute , fifteenmin, halfhour, hourly, daily, weekly, monthly, yearly and on reboot.

3) Current cron jobs

This will show you the latest cron jobs installed. You can edit / remove cron jobs from here.

Final notes

  • There is a cron checker plugin available in the elgg community for you to install and make sure your cron is running.
  • Do not use very short duration cron jobs in a shared host or unnecessarily. Because  consumes more server load and makes your site slow. Use only needed cron jobs. For a basic elgg installation, you only need monthly cron.
  • There is a good documentation available on elgg about cron and how to Develop Cron-aware plugins
Tags: , , , , , , , , ,

10 Responses

  1. Philip says:

    Thanks for this information. It is the best tutorial I have seen on setting up cron for my elgg website. I was searching for this for last 2days. Following your information, I was able to install it in five minutes. Thank you.

  2. Abigail says:

    thanks a lot for taking time to discuss this subject with us.

  3. Albertina says:

    this is very useful article for many users. thanks for putting across these details in this article.

  4. taner says:

    Hi I have tried to set this up but am getting the following message via email

    curl: (7) couldn’t connect to host

    This is the the command that I am running through my scedualed tasked in cpanel

    /usr/bin/curl http://socialone.co.uk/demo/pg/cron/daily/
    Any ideas?

    Thanks

  5. The error means “Failed to connect() to host or proxy. Thats a 404 page. Try hitting the same URL in your browser and see.

  6. […] You need to have a working daily cron job to empty the junk / expired cached files. Otherwise the size of your cache directory will keep on increasing. See this tutorial on How to create a cron job for Elgg?  […]

  7. […] Posted on: April 21st, 2010 by Sarath C No CommentsThis is an elgg (1.8) plugin which will help site admin’s to send messages or notifications to all your site members at once. The plugin will send the notifications as a pack of 25 mails per five minute. This wont create any problems with your hosting and there is less chance of marking your mails as spam. You need to configure the fiveminute cron job for your elgg site.  See this tutorial for how to create elgg cron job. […]

  8. Jon Adams says:

    I’m not clear about the cron job command. Should it be domains/mysite/public_html/elgg/mod/galliMassmail/

    or should it be to a more specific php file within the galliMassmail directory ?

    I’m using Direct Admin (not CPanel)

    Thanks’

  9. Webgalli says:

    @Jon Adams : Hope you got it working. If anybody is in same situation, see this thread on how to configure elgg cron in direct admin.

  10. Lanie says:

    If you don’t have privilege to setup cron job or don’t know how to, a third party webcron may be a good option for you. Check out a tutorial at http://www.easycron.com/tutorials/how-to-set-up-cron-job-for-elgg