Discussion on PHP + MySQL Chat Room Technology

Source: Internet
Author: User

Recently, the topic of PHP chat room technology has been launched in PHPChina, and I am working on this project recently. I also want to express my views here.

Main functions of the chat room:
1. Register, log on, exit, and modify data.
2. the user applies to create a chat room and customize attributes of the chat room.
3. display the chat room name, description, host, announcement, and advertisement.
4. The online user list is displayed in real time. You can view online user information (such as nickname, email, ip address, and online duration ).
5. Publish chat content, font attributes, actions, expressions, and common phrases.
6. allow stealth, private chat, scrolling, blocking users, clear screens, selection of chat scenarios, background music, and custom sending methods.
7. The administrator has the right to manage members (such as kicking out, disallowing speeches, and handing over management permissions ).

1. forbidden to use the framework structure (iframe does not bring any benefit except to reduce your labor volume)
2. The front-end and back-end code are completely separated. Only data is transmitted through the ajax channel, and only necessary data should be transmitted. (Display data at the front end and process data at the backend)
3. Do not refresh the entire page caused by the program. Only update the content that needs to be changed (do not use header or meta to refresh the page ).
4. When submitting chat content, you cannot blindly pursue the speed of user experience, but ignore the actual order of chat record submission. (That is to say, the submitted chat records should be reorganized on the server in the actual order and then transmitted to the client, because many people may submit information at the same time)

Technologies used:
1. AJAX, a bridge between the front and back ends. Jquery and XAJAX can be used. I prefer jquery, which is fast, simple, and durable. There are many plug-ins that can be updated quickly.
2. The data carrier form is XML. In fact, the data in common chat rooms is not very complex, and json is enough.
3. Database abstraction layer-ADODB. Using PDO is faster. I am used to using ADODB.
4. MySQL, the underlying data storage medium. There is no doubt about this.
5. Data intermediate storage medium-memcache. Store high-speed read/write data in the memcache shared memory to reduce the load on the database.
6. If you want to implement video and voice, you need to install flash player on the client side, which is supported by the server-side PostgreSQL (flash media server. It also involves data interaction between html, javascript, flash, and the background. There are not many materials in this regard.

These are the core technologies. In actual application development, many details need to be solved.

For example, how to update the online list?
There are two ways:
1. Refresh the entire list (whether updated or not ).
2. Add new online members, delete offline members, and change materials.
Obviously, the second option is the best choice.

How can I handle the XmlHttpRequest concurrency problem?
Javascript is single-threaded. If there are two XmlHttpRequest objects at the same time, it is very prone to problems. This requires us to control the generation and termination of XmlHttpRequest.
In chat rooms, the data we need to update mainly includes the online list (including member information updates), chat records, and chat room attributes. The update frequency is inconsistent (if the time is the same, you only need to create an XmlHttpRequest to process it ). The chat record needs to be updated in a short period of time, and the online list can be updated for a little longer. If the XmlHttpRequest object is created separately without the framework, concurrency may occur. This requires the creation of a time and flow control function.
SetInterval (process_control (), 3000) // call once every three seconds
The process_control function schedules tasks. For example, if a task is executed at a certain interval, the next task is executed only after the task is completed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.