I'm currently working on a site. I have a script that is run on my PHP page that watches the time on each page load. So, when it loads, it checks what time it is. If the time is past 4 a.m. it deletes all records in the table that were before that time.
I now have a problem. I think this is very insufficient. First off, it only happens once. If I'm the first to load the page after 4 a.m. then it erases the records. However, if you come in and load the page, it will still check the records, even though they've been erased.
Also, my friend said, any deletion of a lot of records shouldn't happen on the front end (PHP page). It should happen on the back end. He said by deleting all these records at this time will force the user to 'hang' on that page while it deletes all these records. He suggested creating a nightly procedure that simply deletes these records at 4 a.m, such as a scheduling event.
Now, I have a mysql database. I also use PHPmyadmin to do all my table work. Is there any way I could accomplish this w/o using a PHP script? I could physically sit at my computer at 4 a.m. and delete these records, but who wants to do that.
I've also thought, if I have to have to use a PHP script, is there any way I could have a script running at all times. A page that runs even if it's not loaded, that watches the time and deletes these records?
I know this is a weird question, but all suggestions are welcome. Thanks for reading and for all your help.
Check if your host support cron jobs. Basically, you can setup a script which server will execute in predefined times. You can search the forums a little bit, cron jobs were mentions lots of times before.