简体   繁体   中英

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.

  2. A PHP page which performs a MySQL Query select all from userMessages and displays all the messages.

The problem I'm having is making this messaging system have an INSTANT Message Functionality. 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. 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. AJAX polling every few seconds would be a good idea, if you don't mind a rather high server and database load. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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