1. Home
  2. Crons
  3. CRON Tasks in N0C — Differences between Wget, Curl and PHP

CRON Tasks in N0C — Differences between Wget, Curl and PHP

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

Note : Le glossaire contient  des explications sur de multiples sujets et peut être consulté pour clarifier certains termes.

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

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 control panel. If your script needs to use another version of PHP, you must specify this by giving the full path to PHP. 

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.

Updated on October 30, 2024

Related Articles