Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget, curl and php for cronjobs

Tags:

php

curl

cron

wget

I have been wondering, is there a difference between wget [parameters], curl [parameters] and php [parameters] whilst creating a cron job?

If I have a script "cron-00-00.php" and I need to run it what would each of the mentioned above do?

0 0 * * * php -q /your_abolute_path/includes/php/cron/cron-00-00.php >/dev/null 2>&1
0 0 * * * wget -O - -q -t 1 http://your_domain_com/includes/php/cron/cron-00-00.php >/dev/null 2>&1
0 0 * * * curl http://your_domain_com/includes/php/cron/cron-00-00.php

Or is it optional to use either one(depending upon the one that best suits me)?

I currently have this thought that the 3 of them have different functions. Please correct my conceptions.

like image 296
Khalid Okiely Avatar asked Oct 17 '12 09:10

Khalid Okiely


People also ask

What is wget in cron job?

The wget command is a command line utility for downloading files from the remote servers. It's also used to triggers server side scripts using the cron jobs.

What's the difference between curl and wget?

Wget is a simple transfer utility, while curl offers so much more. Curl provides the libcurl library, which can be expanded into GUI applications. Wget, on the other hand, is a simple command-line utility. Wget supports fewer protocols compared to cURL.

How do I schedule a curl command?

To schedule a curl command to run at 3am daily, you can insert the line: 0 3 * * * curl args... Notice how the minutes and hour correspond to 3am (side note: cron uses 24 hour time format, no am or pm). The asterisks that follow mean every day of month, every month, every day of week.


1 Answers

Running PHP directly is the simplest option. It doesn't take up a network slot on your apache (or other webserver) instance. It also bypasses limits associated with webservers that are designed to protect your machine against malicious third parties. However, the environment under which the command-line version of PHP runs is slightly different, and may be enough so to prevent a poorly-written script from behaving properly. Also, some webserver run PHP as a DSO module within apache's process space and using apache's user permissions. This might affect your results (maybe positively or maybe negatively).

Of the remaining two options, curl seems to be slightly more widely deployed than wget, so that would be my second choice, though they're approximately equal.

like image 139
tylerl Avatar answered Sep 25 '22 21:09

tylerl