Jump to content

Recommended Posts

Cron Job using PHP CLI (Command Line Interface).

 

Basically the cron job is set to run every x minutes or hours or days etc. (Google Cron Job to read more up on that).

 

What a cron job does (or scheduled task) is automatically run some code at the times specified. An example of a line for a script that runs every day in a cron job would be:

 

0 0 * * * /usr/bin/php -f /home/username/deleteDaily.php

 

Then the code for your script to erase the entries would be something like this:

deleteDaily.php

<?php
// mysql connection info

mysql_query("DELETE FROM table_name WHERE datecol > " . strtotime('+1 week'));
?>

 

This "should" (test it without deleting before using) delete any entry that is > 1 week old. I do not know how MySQL different date fields handle a unix timestamp, so that may or may not work.

 

But that is the basic gist, for a cron job running via PHP CLI check out this Tutorial.

 

For how to do this on a windows server, look into Scheduled tasks.

You can do it via PHP code or through a Cron Job (http://en.wikipedia.org/wiki/Cron), which is a method to automatically run scripts every x period of time.

If you want to use PHP for that you will have to create a function and run it every time you modify your database (add record,update record).

 

Do a google search for deleting mysql records older than.

 

Hope this helps.

 

Angel

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.