Файл: sistem/cron_update.php
Строк: 69
<?php # Created By Up
error_reporting(0);
@set_time_limit(0);
list($m,$s)=explode(chr(32),microtime());
$config=array();
$config['GENERIC']=($m+$s);
include_once '../sistem/config.php';
$error=true;
$time=time();
$data=date('Ymd');
$vchera=$time-60*60*23;
$unlink=$data-3;
$mesjac=$time-60*60*24*30;
$user_del=0;
$user_update=0;
$user_hit=0;
$user_host=0;
$log=fopen($config['root'].'/sistem/data/update.log','a');
fputs($log,'<b>START data: '.date('d M Y').' year.</b><br />'."rn".'Connect server ');
for($i=1; $i<=60; ++$i)
{
if($db=mysql_connect($config['db_server'],$config['db_user'],$config['db_pass']))
{
fputs($log,'OK<br />');
break;
}
else
{
fputs($log,'NOT<br />Reconnect ('.$i.') server ');
sleep(1);
}
}
if($db!==false)
{
if(mysql_select_db($config['db_name']))
{
fputs($log,"rn".'Select base '.$config['db_name'].' OK<br />');
// Настройка кодировки
mysql_unbuffered_query('SET charset utf8',$db);
mysql_unbuffered_query('SET names utf8',$db);
mysql_unbuffered_query('SET character_set_client='utf8'',$db);
mysql_unbuffered_query('SET character_set_connection='utf8'',$db);
mysql_unbuffered_query('SET character_set_result='utf8'',$db);
// Обновление статистики и удаление не активных сайтов
$sql=mysql_query('SELECT * FROM `site`;');
while($arr=mysql_fetch_assoc($sql))
{
if($arr['data']>=$unlink or $arr['status']==2)
{
++$user_update;
$host=mysql_result($res=mysql_query('SELECT COUNT(*),SUM(`hit`) FROM `statistic` WHERE `for`=''.$arr['id'].'' and `data`!=''.$data.'';'),0);
$hit=mysql_result($res,1);
$user_hit+=($hit=($hit>=1?$hit:0));
$user_host+=($host=($host>=1?$host:0));
mysql_unbuffered_query('insert into `history` set `for`=''.$arr['id'].'',`hit`=''.$hit.'',`host`=''.$host.'',`time`=''.$vchera.'';');
mysql_unbuffered_query('UPDATE `site` SET `hit`='0',`host`='0',`v_top`='0',`s_top`='0''.($host>=1?',`data`=''.$data.''':'').' WHERE `id`=''.$arr['id'].'' LIMIT 1;');
}
else
{ // Удаляем неактивный сайт
++$user_del;
mysql_unbuffered_query('DELETE from `site` WHERE `id`=''.$arr['id'].'' LIMIT 1;');
mysql_unbuffered_query('DELETE from `golos` where `for`=''.$arr['id'].'';');
mysql_unbuffered_query('DELETE from `zalobi` where `for`=''.$arr['id'].'';');
mysql_unbuffered_query('DELETE from `history` where `for`=''.$arr['id'].'';');
mysql_unbuffered_query('DELETE from `statistic` where `for`=''.$arr['id'].'';');
}
}
// Удаление старых данных
mysql_unbuffered_query('DELETE from `zalobi` where `status`='2' AND `time`<''.($time-60*60*24*3).'';');
mysql_unbuffered_query('DELETE from `history` where `time`<''.$mesjac.'';');
mysql_unbuffered_query('DELETE from `statistic` where `data`!=''.$data.'';');
// Оптимизация таблиц
mysql_unbuffered_query('OPTIMIZE TABLE `top`,`kom`,`site`,`users`,`golos`,`ban_ip`,`zalobi`,`history`,`ban_site`,`statistic`,`news`;');
$error=false;
}
else
fputs($log,"rn".'Select base '.$config['db_name'].' ERROR<br />');
}
list($s,$m)=explode(chr(32),microtime());
fputs($log,"rn".' Update: '.$user_update.'<br />'."rn".' Unlink: '.$user_del.'<br />'."rn".' All host: '.$user_host.'<br />'."rn".' All hit: '.$user_hit.'<br />'."rn".'FINISH UPDATE '.round((($s+$m)-$config['GENERIC']),4).' sec.<hr />'."rnrn");
fclose($log);
flush();
exit($error==false?'OK':'ERROR');
?>