 <?php

$t=microtime(1);
$time=time();
require_once'inc/start_sess.php';
mysql_query("DELETE FROM `kolhoz_zags` WHERE `time` < '".($time-(3600*6))."' AND (`status`='0' OR `status`='1' OR `status`='3') ");
mysql_query("DELETE FROM `kolhoz_mail` WHERE `time` < '".($time-(3600*24*15))."' AND `favorite` = '0'");
mysql_query("DELETE FROM `kolhoz_collective_chat` WHERE `time` < '".($time-(3600*24*1))."'");
///////mysql_query("DELETE FROM `kolhoz_chat` WHERE `time` < '".($time-(3600*2))."'");

mysql_query("DELETE FROM `kolhoz_joirnal` WHERE `time` < '".($time-(3600*24*2))."'");
mysql_query("DELETE FROM `kolhoz_warehouse` WHERE `count` = '0' AND `tachka`='0'");

/////Рейт за неделю
if(date("D", time())=='Mon')mysql_query("UPDATE `kolhoz_collective_user` SET `rating_week`='0',`rubies_week`='0'");
/////
$at = mysql_query('SHOW TABLES');  //получим список таблиц
while ($tables = mysql_fetch_assoc($at)) 
{foreach ($tables as $bd => $table) { 
mysql_query('OPTIMIZE TABLE `'.trim($table).'`')or die(mysql_error());}}
echo '<br/> '.number_format(microtime(1)-$t,3).' сек.';
?> 