Home > Magento Tutorials > Setting Up A Cron Job for Magento

Setting Up A Cron Job for Magento

Posted on: 5th May 2010 By: Robert Kent 12 Comments

A Cron job is a scheduled task, a task that is performed every so often by the server without any user input. Cron jobs are important for lots of different reasons and when it comes to ecommerce they are a godsend.

Magento required Cron jobs for a few different reasons but the most important ones in my opinion are:

  • Newsletter Sending
  • Automatic Sitemap Generation

What you should do is set up your newsletters and sitemaps as normal through Magento. Schedule your times and basically follow the instructions on screen. When you set your dates/times etc the Cron Job will perform these tasks after that date/time has been reached. It is therefore beneficial to schedule your Cron Job to run every 10-15 minutes.

Magento uses a single file named cron.php to execute all its scheduled tasks – all that is required to be done is to schedule a cron job to execute that php every so often.

At Ecommerce Website Design we use a server that has Plesk installed – with plesk it is easy to schedule your Cron Jobs.

I will show you now how to set up your Cron Job through plesk.

First of all navigate into your domain and on your domain dashboard click CronTab.

Secondly once you are inside your Crontab select the name of your FTP user. In this case it is “swimming”.

Next you should click on the Add Scheduled Task for FTP user from the tools menu at the top of the screen.

Now the important bit – what you should do is schedule the task for every 10 minutes. To do this we use the following command in the minutes section – */10. Next we want this to execute every hour of every day of every month – so we simply add a * to all the other boxes.

The last thing to do is to actually perform a command for this scheduled event. In our case on our plesk servers (should be reasonably similar for most linux server paths) we use the following command:

/usr/bin/php -f /var/www/vhosts/mydomain.com/httpdocs/cron.php

Simply replace mydomain.com with whatever your domain is called e.g. e-commercewebdesign.co.uk

Here is a screenshot to better demonstrate:

Once your cron job has been saved you will see that Magento will now run your scheduled tasks at the date/time you inputted (or 10minutes after the actual time).

Thanks for visiting our magento blog – I hope you found this post useful – any questions please let me know!

12 Responses to “ Setting Up A Cron Job for Magento ”

  1. Tim
    #1 | 5th May 2010

    Nice post! Thanks for the awesome. I’ve been wondering how to get a cron job to integrate with Magento!

  2. Vikas Pal
    #2 | 14th May 2010

    Hi,

    Actually i am new to magento and i would like to ask one thing regarding setting up cron job for Newsletter sending, i am using magento 1.4 version, i had add new template for newsletter and set the schedule time for that.

    Default cron job setting is in magento, i have not changed yet, and set the cron.php on server. After all this the newsletter is not sending.

    Is i want to add some thing extra here to send a newsletter?

    Its my humble request for you to send me the procedure how to send the newsletter in magento 1.4 .

    Thanks in advance.

    Regards
    Vikas Pal
    vikaspalkec07@gmail.com

  3. Rob
    #3 | 21st May 2010

    Hi Vikas,

    To send a newsletter you should schedule our cron job to run every 15 minutes or so – then you go into your newsletter section and schedule the run – make sure its in the future. Your cron job will only pick up on the schedule after its been done – so don’t be suprised if it doesn’t sent it straight away:

    e.g if you set your cron job for every 15 minutes and your newsletter is due to send at 9am. You could find that it doesn’t send until 9.14am (the next time the cron job is run AFTER the event is supposed to happen)

    To create your newsletter go to newsletter templates > create our newsletter.

    Then go to newsletter templates and on the main page select queue newsletter from the drop down – you can select the start date from the top – hit save and this will be queued.

  4. Magento SEO: Index your pages, Magento Blog and E-Commerce
    #4 | 13th July 2010

    [...] you have read my other post “Setting Up A Cron Job for Magento” you will know that magento has its own automated protocols for generating sitemaps and [...]

  5. coventry web design
    #5 | 5th August 2010

    I’m new to magento and you’re tutorials have helped me out so much thank you!

  6. Ryan Frattoys
    #6 | 19th August 2010

    Call Johnny at Tranquil Blue he’ll fix the problem for you.

  7. Hardik
    #7 | 20th September 2010

    This is really good post that helpful for magento beginners.

  8. Jay
    #8 | 29th September 2010

    I’m a newbie but I am looking to have a drop ship extension and at the end of the day automatically send out PO’s to my suppliers.. Will setting up a cron job accomplish this?? Any help or direction is appreciated..

  9. DomainHosting
    #9 | 6th December 2010

    To Jay – hope you got your problem resolved
    To the article author – thank you for the info, I’ve solved my problem with Magento

  10. Magento Host
    #10 | 18th March 2011

    Great resource, Linux cron jobs are definitely beyond the beginner webmaster. You might also consider expanding tutorials for cPanel and InterWorx. :)

  11. Ecommerce web designer
    #11 | 3rd August 2011

    Thanks for such valuable resource. The author defined the cron jobs of Magento Ecommerce web design for the newbie. It works even for everyone. a clear demonstrated article.

    Good work.

    Thanks

  12. Thomas
    #12 | 12th October 2011

    Thanks for this post ;-)
    However, if this doesn’t work for you, try to add a simple

    echo "done!";

    into your cron.php code, right before the last

    ?>

    .
    You can find your cron.php at:
    yourdomain.com/MAGENTOROOT/cron.php

    seems strange, yes, but thats how it finally works for me ;-D

Post A Comment

Your comments:
Enclose code snippets within the appropriate tags: [php][/php]   [js][/js]   [xml][/xml]   [css][/css]   [html][/html]
E.g: [php]<?php echo "hello world"; ?>[/php]

Search Blog

Archives

For the record...

Views & opinions in this blog are those of the individual and do not necessarily reflect those of E-commerce Web Design or the Creare Group.