Using WGET to run a cronjob PHP

PhpLinuxCronWget

Php Problem Overview


I tried to do a cron and run a url every 5 mintues.

I tried to use WGET however I dont want to download the files on the server, all I want is just to run it.

This is what I used (crontab):

*/5 * * * * wget http://www.example.com/cronit.php

Is there any other command to use other than wget to just run the url and not downlaod it?

Php Solutions


Solution 1 - Php

You could tell wget to not download the contents in a couple of different ways:

wget --spider http://www.example.com/cronit.php

which will just perform a HEAD request but probably do what you want

wget -O /dev/null http://www.example.com/cronit.php

which will save the output to /dev/null (a black hole)

You might want to look at wget's -q switch too which prevents it from creating output

I think that the best option would probably be:

wget -q --spider http://www.example.com/cronit.php

that's unless you have some special logic checking the HTTP method used to request the page

Solution 2 - Php

wget -O- http://www.example.com/cronit.php >> /dev/null

This means send the file to stdout, and send stdout to /dev/null

Solution 3 - Php

I tried following format, working fine

*/5 * * * * wget --quiet -O /dev/null http://localhost/cron.php

Solution 4 - Php

If you want get output only when php fail:

php -r 'echo file_get_contents(http://www.example.com/cronit.php);'

This way you receive an email from cronjob only when the script fails and not whenever the php is called.

Solution 5 - Php

you can just use this code to hit the script using cron job using cpanel:

wget https://www.example.co.uk/unique-code

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbdullah AlsharifView Question on Stackoverflow
Solution 1 - PhpJames CView Answer on Stackoverflow
Solution 2 - PhpEmil VikströmView Answer on Stackoverflow
Solution 3 - PhpMosiurView Answer on Stackoverflow
Solution 4 - PhpangelroveView Answer on Stackoverflow
Solution 5 - PhpHammad Ahmed khanView Answer on Stackoverflow