этот скрипт дёргается аяксом каждые 8сек. В итоге при 6 юзерах имеем одновременно около 1к запросов к бд.
<?php
include('../../../inc/config.php');
//проверяем авторизацию
$id = preg_replace('/[^0-9]/', '', @$_COOKIE['id']);
if ($id) {
$hashh = @$_COOKIE['hash'];
$result_set = $mysqli->query("SELECT * FROM users WHERE id = '$id'");
$user = $result_set->fetch_array(MYSQLI_ASSOC);
if (@$result_set->num_rows === 1) {
$_SESSION['id'] = $id;
$hash = hash('sha512', $user['login'] . $user['flag'] . $user['date_reg'] . $user['password'] . 'Злобный000Чел000я000жду000тебя');
if ($hash !== $hashh) {
exit();
} else {
//если авторизация успешна делаем выборку с бд.
switch ($_GET['chat']) {
case"public":
$query = $mysqli->query("SELECT chat.id, chat.time, chat.to,chat.msg, chat.user_id, u.login FROM chat_public as chat INNER JOIN users as u ON u.id = chat.user_id ORDER BY chat.id DESC LIMIT 25");
break;
case"alliance":
$query = $mysqli->query("SELECT chat.id, chat.time, chat.to,chat.msg, chat.user_id, u.login FROM chat_alliance as chat INNER JOIN users as u ON u.id = chat.user_id ORDER BY chat.id DESC LIMIT 25");
break;
case"bootcamp":
$query = $mysqli->query("SELECT chat.id, chat.time, chat.to,chat.msg, chat.user_id, u.login FROM chat_bootcamp as chat INNER JOIN users as u ON u.id = chat.user_id ORDER BY chat.id DESC LIMIT 25");
break;
}
//читаем инфу тек. юзера с бд
$result_set = $mysqli->query("SELECT rights,login FROM users WHERE id = '$id'");
$uses = $result_set->fetch_array(MYSQLI_ASSOC);
//цикл вывода смс
while ($result = $query->fetch_assoc()) {
//инфа отправителя
$result_set = $mysqli->query("SELECT flag,lvl FROM users WHERE id = '$result[user_id]'");
$user = $result_set->fetch_array(MYSQLI_ASSOC);
$message = $result['msg'];
//если позволяют права тек. юзера то добавляем кнопку удалить
if ($uses['rights'] >= '500') {
$delete = "<a href='javascript:void(0);' onclick='deleted($result[id])' class='green'>удалить</a>";
}
//если совпадает твоё имя и имя кому отправили
if ($uses['login'] === $result['to']) {
?>
<div class='block_white marg_bot_10'>
<div class='block_inside'>
<div class='block_info'>
<div class='user no_padd'>
<label for='2' class='no_margin'>
<span class='flag inline'><span class='flag_country_<?= $user['flag'] ?>'></span></span>
<div>
<span class='info'>Ур.<span class='yellow'><?= $user['lvl'] ?></span></span>
<a href='javascript:void(0);' onclick="selectNick(this)" class='green'><?= $result['login'] ?></a>
<a href='/profile/enemy/info/<?= $result['user_id'] ?>'><span class="icon_info"></span></a> <?= @$delete ?>
</div>
</label>
</div>
<div class='fl_right'><p><?= date('H:i:s', $result['time']) ?></p></div>
<div class='clearFix'></div>
<p><?= $message ?></p>
</div>
</div>
</div>
<div class='divider marg_top_5 marg_bot_5'></div>
<?php
} else {
?>
<div class='block_inside'>
<div class='block_info'>
<div class='user no_padd'>
<label for='2' class='no_margin'>
<span class='flag inline'><span class='flag_country_<?= $user['flag'] ?>'></span></span>
<div>
<span class='info'>Ур.<span class='yellow'><?= $user['lvl'] ?></span></span>
<a href='javascript:void(0);' onclick="selectNick(this)" class='green'><?= $result['login'] ?></a>
<a href='/profile/enemy/info/<?= $result['user_id'] ?>'><span class="icon_info"></span></a> <?= @$delete ?>
</div>
</label>
</div>
<div class='fl_right'><p><?= date('H:i:s', $result['time']) ?></p></div>
<div class='clearFix'></div>
<p><?= $result['msg'] ?></p>
</div>
</div>
<div class='divider marg_top_5 marg_bot_5'></div>
<?php
}
}
}
} else {
exit();
}
} else {
exit();
}
Зарание спасибо