How do I run a php script on a daily basis automatically?

Paithar

[H]ard|Gawd
Joined
Jul 17, 2003
Messages
1,049
I was doing some web development work for a guy when he asked me something. He has a php script that needs to run on a dialy basis because it backs up a certain table before clearing out certain fields. Right now he runs it manually every day.

I initially said he should put it in a cron job and he tried that but it didn't work because he said that in order for it to run automatically he still needed to be logged in to the server as an admin.

So, how else could a php script be made to run every day at a certain time without any intervention of an actual person?
 
cron processes do not require you do be logged in.

I help manage several PHP sites that need daily / hourly maintenance run via a php script.

Here are the two most common ways I solve the problem:

wget -q -O /dev/null http://yoursite.com/admin/cron.php

or

/usr/local/bin/php http://yoursite.com/admin/cron.php


Add this to your crontab like so:

crontab -e
45 4 * * * wget -q -O /dev/null http://example.com/moodle/admin/cron.php
(press esc, ZZ)

(to run at 4:45AM every day)


(if you have shared hosting and your host allows you to schedule cron processes, there will be a page to enter the cron command - i.e., cpanel)
 
Thanks, I'll have the guy give those options a try and see what happens.
 
Back
Top