Javascript 如何在Php页面上实现实时通知

Javascript 如何在Php页面上实现实时通知,javascript,php,html,Javascript,Php,Html,这是我的家。Php,我需要显示来自数据库的实时通知 <html> <body> <label>Notifications <?php echo "(".$notification.")"; ?>)</label> //$notification Contain no. of Notifications From Database </body> </html> (通知) //$notification包含来自

这是我的家。Php,我需要显示来自数据库的实时通知

<html>
<body>
<label>Notifications <?php echo "(".$notification.")"; ?>)</label>
//$notification Contain no. of Notifications From Database
</body>
</html>

(通知)
//$notification包含来自数据库的通知数

您需要使用
web套接字
进行实时通知。您可以尝试使用
Ratchet
socket.io

AJAX和setInterval可以部分实现。为了接近真正的实时性,您可能需要查看WebSocket。哪个更安全?目前我正在使用@Node Js。我还有一个问题。我需要执行如下查询:-select*from tb\u users where user\u id=“value from Php Session”。我需要从php会话中获取用户id以执行查询。我该怎么做(使用web socket的第一步是什么?@Krishnan正在学习如何使用web Sockets当前我使用@Node Js。这里我有另一个问题。我需要执行一个查询,如:-select*from tb\U users where user_id=“value from Php Session”。我需要从Php Session中获取用户id来执行查询。我该怎么做?:(