4

I am using Magento CE 1.7.0.2 on Linux, cPanel environment.

Search for proper command for cron job in cpanel

So far I got:

  1. PATH to PHP /home/USERNAME/PATH_TO_MAGENTO/cron.php
  2. wget -O /dev/null -q http://www.YOURDOMAIN.com/PATH_TO_MAGENTO/cron.php

What is difference in both command and which one is better?

4 Answers 4

5

I simply use the GUI provided by the cPanel: Cron Job in Cpanel

Just you need to select the interval for the cron and use command as:

php -f /home/<cpanelUser>/public_html/path-to-magento/cron.php

and you are done!

3

I usually use the PHP command to run the cronjob.

  • No timeouts
  • Is unaffected by DNS issues or when you for example change your domain name.
  • Easier to terminate and monitor when you know which PHP thread is running the script

If you do want to use wget I suggest replacing the domain name with the IP if possible so you can prevent issues named at point 2

3

The only reason for using the wget version

wget -O /dev/null -q http://www.YOURDOMAIN.com/PATH_TO_MAGENTO/cron.php

is when you're on a hosting service that doesn't allow for setting up cron jobs. You can then set up a process on another system to poll cron.php periodically to trigger Magento's cron job system.

It's useful also for testing if the cron jobs are functional, but inelegant and usually if required to actually run cron jobs, an indicator that your hosting service probably is not really set up to run Magento.

If you have cron access (which you do) the php execution local to the server is best for the reasons @sander points out.

Note: Newer versions (1.9.2.x) lock down the access to prevent just any old internet troll from hammering your cron script. The following section in your .htaccess allows you to set up the ability to remotely trigger it via an authenticated user.

###########################################
## Deny access to cron.php
    <Files cron.php>

############################################
## uncomment next lines to enable cron access with base HTTP authorization
## http://httpd.apache.org/docs/2.2/howto/auth.html
##
## Warning: .htpasswd file should be placed somewhere not accessible from the web.
## This is so that folks cannot download the password file.
## For example, if your documents are served out of /usr/local/apache/htdocs
## you might want to put the password file(s) in /usr/local/apache/.

        #AuthName "Cron auth"
        #AuthUserFile ../.htpasswd
        #AuthType basic
        #Require valid-user

    ############################################

        Order allow,deny
        Deny from all

    </Files>
2
  • It helped me. So i upvoted on this. Thank you. Commented Jul 6, 2016 at 7:29
  • You're welcome! Access control has been added to newer versions, added that info. Commented Jul 8, 2016 at 3:43
2

There is also an included Shell script

*/5 * * * * /bin/sh /path/to/root/of/site/cron.sh &> /dev/null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.