Schedule running of PHP script daily

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bobi69
Forum Newbie
Posts: 1
Joined: Wed Nov 06, 2002 10:13 am

Schedule running of PHP script daily

Post by bobi69 »

Hi,
My web site use PHP and MySQL and it is on UNIX server.
How can I schedule one PHP script to run every day ? This script delete
some records of MySQL database.
1. I tried to use AT command from UNIX system - without any success.
2. I created stored procedure on MySQL server, but I dont know how
I can schedule it.

Please help me !
seg
Forum Commoner
Posts: 38
Joined: Thu Oct 31, 2002 12:08 pm
Location: Northern, VA
Contact:

Re: Schedule running of PHP script daily

Post by seg »

If you have a fully dedicated server (as in you have root access and you are the only user on the server) you can use cron jobs to do the cleanup. Unfortunatly I'm out of practice to give any examples, but looking at the cron manual you should be able to figure it out. If memory servers, it is just a matter of picking when you want it to run, hourly, daily, monthly, everytime you boot, etc, and then adding the command to one of the cron files. At the command prompt, type "man cron" and that will bring up the manual for the cron daemon.

Now if you don't have root access, and/or are not the only person on the server there is a way to do it, but it is one of my classic "Way too much work to get the job done" methods. Also known as "The dumbest way to do it" method. This would be to create an html page that refreshes itself every hour, or whatever, and in the php code for the page it checks the current time agaisnt the schduled time for clean-up. If it matches it executes the clean-up. You would need to keep a web browser open with that page on it 24/7. Another cheap way would be to create the page, but without the refresh tag, then run some sort of program on your computer to open the page at a certain time. You could use php and/or .htaccess to restrict access of that page to your IP address only.

Good luck.
-seg
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You may still be able to run cron even on a shared server but you have to ask your host about what their policy is.

Mac
Post Reply