Use of cron jobs


We consider that this message sometimes given by scripts and applications for the implementation of cron tasks: 'contact your server administrator' is worthy of the 80s :). In fact, whether it's the cPanel administration panel or another, this kind of elementary function has been made accessible to the end users, this is now a 'just do it' task, just read the basic cPanel instructions and this article if necessary...

From your cPanel, section Advanced / Cron jobs :

Gestion de Cron par cPanel

Attention :
Cron executing at too close intervals without need/justification leads to bugs, and overflow of resources leading to the malfunction of your website

According to your needs and recommendations of the editor, here are the 2 formats A and B in examples :
A. PHP scripts running in internal php :
/usr/bin/php -f /home/yourcpaneluser/public_html/yourfolder/your-sub-folder/yourfile.php >/dev/null 2>&1

php -f /home/your_user/public_html/yourfolder/your-sub-folder/yourfile.php >/dev/null 2>&1
(The '-f' flag tells php to parse/execute the following file)
(Check :

For cPanel servers :
/usr/local/bin/php -f /home/votreusercpanel/public_html/votredossier/votre-sous-dossier/votrefichier.php >/dev/null 2>&1

B. PHP scripts running externally :

wget -q -O /dev/null "" >/dev/null 2>&1
/usr/bin/wget -q -O /dev/null "" >/dev/null 2>&1

curl -s "" >/dev/null 2>&1

NB :
1. Adding this in cronjob is a good thing : 
sleep $(expr $RANDOM \% 35);
It helps server to not struggle with executing all cronjobs of servers at same second (ssh must be activated)... 
Integration example, it must be put at begin of cron like this :

sleep $(expr $RANDOM \% 35); /usr/bin/wget -q -O /dev/null "" >/dev/null 2>&1
2. Avoid putting all your cron with minute value all same at 0, also space the minutes value of your cron to avoid a local conflict of your application.
3. Adding >/dev/null 2>&1 permit to stop sending emails at each cron execution
4. For wget cron, adding  -q -O /dev/null permit to avoid wirting a file in your account at each cron execution

Specific scripts, and SHELL Scripts if ordinary cron don't work

A. cron with script sh
sh /home/yourcpaneluser/

B. Specificity of certain php script involving shell commands and/or shell_exec, in our virtualized environment using CageFs from Cloudlinux, it is necessary that you add this in your crontab though shell :


And simply add cron in your cPanel :
* * * * * php -f /home/yourcpaneluser/ >/dev/null 2>&1

NB : if needed, check well and adapt your php.ini settings in your cpanel, about the default disable_functions, read doc of CMS/module and/or ask editor.

Warning :
the -f option may not be appropriate for some scripts, such as when optimizing wordpress by disabling wp-cron.php in wordpress...

Disable wp-cron in wordpress by adding this in wp-config.php:
define ('DISABLE_WP_CRON', true);

and then adding the cron in cpanel (5 minutes schedule is recommended minimum, and a*update with your domain name):
/usr/bin/wget -q -O /dev/null ""

Also Read

Change password cPanel

To change master password of cPanel, you must do this from your customer area on...

Database remote connection MySQL

From december 11th 2018 (For HA offers, see old method at bottom)   Use your dedicated IP for...

SSH access by key with putty

From July 2018, you can access the SSH terminal directly from your cPanel account (ask us...

How to add an addon domain for a new website with unique domain, subdomain, alias/parked domains

Go to Domains section of your cPanel, you will see these icons to click depending on your need...

How to check the resources used in cpanel

You can regularly verify the usage resources history by your account via your cPanel, section...