I have a web application that has to perform a repeated tasks, Sending messages and alerts, I, already, use a script page do those tasks when it loaded in the browser i.e http://example.com/tasks.php and I included it by the mean of iframe in every page of my web application.
Now I want to change this to use CRON jobs because the first approach may leads to jam performance, So How could I make a CRON job that visits http://example.com/tasks.php. However, I don't want this CRON job creating output files such as day.*!
I host the application on shared hosting service that permits CRON jobs via cPanel.
Cron allows Linux users to run commands or scripts at a given date and time. Here I'm going to explain how to setup cron job in Linux in which you want to run URL at specific date-time. Each user has its own crontab file in Linux. Crontab files can be found in /var/spool folder with file names as username.
It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .
Cron jobs are typically located in the spool directories. They are stored in tables called crontabs. You can find them in /var/spool/cron/crontabs. The tables contain the cron jobs for all users, except the root user.
* * * * * wget -O - http://yoursite.com/tasks.php >/dev/null 2>&1
That should work for you. Just have a wget
script that loads the page.
Using -O -
means that the output of the web request will be sent to STDOUT (standard output)
by adding >/dev/null
we instruct standard output to be redirect to a black hole. by adding 2>&1
we instruct STDERR (errors) to also be sent to STDOUT, and thus all output will be sent to a blackhole. (so it will load the website, but never write a file anywhere)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With