通知系统正在减慢网站速度

时间:2019-05-24 06:57:48

标签: php mysql

我有一个用php编写的网站,其中我已经实现了一个通知系统,但是当记录开始增加通知时,一切工作都很好,这使页面速度变慢了,我该如何解决这个问题?

这是将通知添加到页面

if(isset($_SESSION['user_id'])){
           $count = count_notification();
           //To show notifications
           if($count <=0){
               echo "<li><a href='notifications.php'>Notifications</a></li>";
           }else{
               echo "<li><a href='notifications.php' role='button' class='btn btn-danger btn-xs'>".$count." Notifications</a></li>";
           }
}

这是count_notification函数

function count_notification(){
//To count number of notifications

        $dbc = mysqli_connect(DB_HOST, DB_USN, DB_PASSWORD, DB_DATABASE);
        $user_id=$_SESSION['user_id'];

        $sql_notify="SELECT count(*) coincidences FROM user_notification WHERE to_id = '$user_id'  AND NOT EXISTS (SELECT 1 FROM not_saw WHERE not_id = user_notification.id)";
        $data_notify= mysqli_query($dbc,$sql_notify);
        $row_notifyn=mysqli_fetch_array($data_notify);
        mysqli_close($dbc);
        return $row_notifyn['coincidences'];

}

我如何改善代码?还是有什么办法可以解决问题?

0 个答案:

没有答案