Reputation: 3786
The current MYSQL Is
DELETE FROM `sessions` WHERE `expires` < UNIX_TIMESTAMP();
Not sure how i would make it do what i want to do. I was thinking of using php and doing unixtime-1800 and then using that in the MySQL, which would be okay for my app. Not sure if you can do it all in MySQL becuase i'm just wondering.
The PHP i had would be somthing like this
<?Php
$time = time() - 1800;
mysql_query("DELETE FROM `sessions` WHERE `expires` < $time;")
?>
Upvotes: 0
Views: 1109
Reputation: 3592
That approach will cause huge performance degradations on the high-loaded system. The very first proposal is to create a new table every half an hour and flush older tables by some logic.
Edit: OK, maybe not so huge degradations with half-an-hour GC, but it's a bad design generally.
Upvotes: 0
Reputation: 26597
You can simply do :
DELETE FROM `sessions` WHERE `expires` < (UNIX_TIMESTAMP() - 1800);
Upvotes: 1
Reputation: 10350
Just substract the number of seconds you want
DELETE FROM `sessions` WHERE `expires` < (UNIX_TIMESTAMP() - 1800);
How often do you plan on running this query ?
Upvotes: 1