makerequest ajax,How to make PHP send request to Ajax?

本文探讨了WebSocket作为实时更新的标准,以及在不需要实时更新且用户数量有限的情况下,如何使用AJAX长轮询来实现数据更新。通过定时器加载AJAX获取的XML并使用DOM更新页面,但要注意长轮询可能带来的服务器压力。建议在用户数量较大时谨慎使用,以避免可能的DDoS风险。
摘要由CSDN通过智能技术生成

As Barmar said, WebSockets is the de facto standard to handle continuous polling scenarios.

However, if your application does not need to be updated in real time and you will never have over a certain amount of users, you could use a JavaScript timer to load the resulting XML from an AJAX transaction and update the page via the DOM. Be conscious of how difficult it is to scale continuously polling applications.

Should you opt to go with continuously polling AJAX, an expected design would be along these lines:

User A posts data to a PHP program on the server.

The PHP program saves the user's action into a 'cache' table in a database.

User B's client eventually makes an AJAX request to the server.

Any items in the 'cache' table that contain that user's user ID ($_SESSION['user_id'] or something to that effect) will be returned

to user B's client.

User B's client alerts them that a message was received.

Keep in mind that even if you only poll every 30 seconds, with enough users you could end up DDoS-ing your own server while polling for messages.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值