Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using WGET to run a cronjob PHP

Tags:

linux

php

cron

wget

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?

like image 401
Abdullah Alsharif Avatar asked Apr 23 '11 20:04

Abdullah Alsharif


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.

Can cron run PHP script?

Once the PHP script is called for the first time by the crontab daemon, it can execute tasks in a time period that matches the logic of your application without keeping the user waiting. In this guide, you will create a sample cron_jobs database on an Ubuntu 20.04 server.

How do I run a cron job automatically?

Cron is a job scheduling utility present in Unix like systems. The crond daemon enables cron functionality and runs in background. The cron reads the crontab (cron tables) for running predefined scripts. By using a specific syntax, you can configure a cron job to schedule scripts or other commands to run automatically.


2 Answers

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

like image 174
James C Avatar answered Oct 09 '22 10:10

James C


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

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

like image 32
Emil Vikström Avatar answered Oct 09 '22 11:10

Emil Vikström