1. Home
  2. References
  3. Technical Advice
  4. CRON Tasks — Differences between Wget, Curl and PHP

CRON Tasks — Differences between Wget, Curl and PHP

This article is intended to help you differentiate between Wget client, Curl and PHP commands.

Main Differences

To see the differences, let’s start by looking at the following four commands:

wget -O - -q 'https://www.planethoster.net/modules/cron.php?secure_key=ILOVEPH' --user-agent="PlanetHoster/CRON" > /dev/null 2>&1
curl --user-agent "planethoster" https://www.planethoster.net/modules/cron.php
php -q /home/USERNAME/public_html/modules/cron.php argument=valeur >/dev/null 2>&1
/opt/cpanel/ea-php70/root/usr/bin/php /home/cpaneluser/public_html/path/to/cron.php

The most important difference is that both Wget and Curl use the HTTP protocol. Therefore, Apache configurations or restrictions are added. The Apache timeout is a good example.

However, when you run a Cron task in PHP, you don’t have this kind of limitation, because it is just like going through an SSH connection.

So the most robust way to run a fairly large Cron task is to do it in PHP. Unlike Curl or Wget, the timeout of the web server will have no effect if your script has to run for a while.

Different Versions of PHP and Cron Tasks

If you leave the “php” command as is, the task will use the native/recommended version defined in the WHM (MultiPHP Manager) control panel. If your script needs to use another version of PHP, you must specify this by giving the full path to PHP. 


For example, for World cPanel CloudLinux and HybridCloud cPanel Cloudlinux, you should use this command, where XX should be replaced with the desired PHP version between php56, php70, php71, php72 and php73 :

/opt/alt/phpXX/usr/bin/php /home/cpaneluser/public_html/path/to/cron.php

For non-CloudLinux HybridCloud cPanel, use this command, where XX must be replaced by the desired PHP version between php56, php70, php71, php72 and php73 :

/usr/local/bin/ea-phpXX

For N0C, use this command, where XX must be replaced by the desired PHP version between php44, php51, php52, php53, php54, php55, php56, php70, php71, php72, php73, php74, and php80 :

/opt/alt/phpXX/usr/bin/php

Tips

1-When you launch a Cron with the Curl or Wget command, you must absolutely specify a “user-agent” as in the example above. Otherwise, it is possible that your request is blocked at the server level because of the ModSecurity web application firewall.

2- We also advise you not to run the script every minute. It is better to run it during the night.

3- If you receive too many emails from Cron tasks, you can disable this notification by adding this at the end of your task:  >/dev/null 2>&1.

4- If you have “GET” arguments to give to your script, you should not separate the file argument with a “?”. You simply need to put a space.

Example of a CRON Task in the cPanel

Updated on 27 January 2022

Was this article helpful?

Related Articles