Cron job or not to Cron job it?

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
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Cron job or not to Cron job it?

Post by cap2cap10 »

Greetings PHP Technorati. I hope all is well. I come to you seeking more guidance on the subject of using a cron job to delete a mysql field entry 15 minutes after the entry is entered by the user. I haven't done this before, but should I use some sort of time expiration php script or leave it to the mysql cron job to run every 15 minutes, deleting new entries? Any thoughts on this matter as always is greatly appreciated. :banghead:

thanks in advance.

Batoe

.:To code or not to code is never the question!:. :?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Cron job or not to Cron job it?

Post by Christopher »

You can use a cron job to run a PHP script or use MySQL Event Scheduler (if you have MySQL 5.1 or greater).

I would recommend running the delete job every minute, given what you described. That will make sure that no matter when the entry was created -- it will be delete 15 minutes later. If you run it every 15 minutes then records will be deleted between 15 and 30 minutes later.
(#10850)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Cron job or not to Cron job it?

Post by requinix »

Are you sure you have to completely delete it? Would it not be enough to make sure it's excluded from whatever searches once it's 15 minutes old?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Cron job or not to Cron job it?

Post by Christopher »

True, you could timestamp records and have the code decide whether the data in question is available.
(#10850)
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: Cron job or not to Cron job it?

Post by cap2cap10 »

Yes , the information is at best meant to be temporary for the user of the application. Hence, as a security measure, records are not to be backed up and must be deleted within a set time. Besides, how do you hack something that is not stored in the db long enough for you to get your hands on it?

Sun Tsu: Art of War- Eliminate your enemy's options.

Thanks again,

Batoe :drunk:
Post Reply