简体   繁体   English

PHP即时消息更新

[英]PHP Instant Messages Update

I am creating a messaging system which have the following parts: 我正在创建一个包含以下部分的消息传递系统:

  1. A form which send user message and upon submission of the form, PHP inserts the data into a MySQL Table called userMessages. 一个发送用户消息的表单,并在提交表单后,PHP将数据插入名为userMessages的MySQL表中。

  2. A PHP page which performs a MySQL Query select all from userMessages and displays all the messages. 一个执行MySQL查询的PHP页面从userMessages中全选并显示所有消息。

The problem I'm having is making this messaging system have an INSTANT Message Functionality. 我遇到的问题是使此消息传递系统具有INSTANT消息功能。 ie I submit data from one form and it instantly appears on the user messages page WITHOUT having to manually refresh the page. 即,我从一种表单提交数据,它立即显示在用户消息页面上,而无需手动刷新页面。

I do have temporary solution of refreshing the page every 20 second. 我确实有临时解决方案,每20秒刷新一次页面。 But is there a way to update the messages page only at the moment a new message is submitted? 但是,是否只有在提交新消息时才可以更新消息页面?

Pushing data to a web page is very hard, as Dan Grossman has said you will want to read that wiki article. 将数据推送到网页上非常困难,因为Dan Grossman曾说过您将要阅读该Wiki文章。 AJAX polling every few seconds would be a good idea, if you don't mind a rather high server and database load. 如果您不介意服务器和数据库负载过高,则每隔几秒钟进行一次AJAX轮询将是一个好主意。 ama2 is also right - PHP is inherently not the best system for this, and a continuously running application server using, say, node.js, may be a lot more efficient. ama2也是正确的-PHP本质上不是最佳的系统,使用node.js的连续运行的应用程序服务器可能会效率更高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM