PHP grouping chat room fooking reality-php Tutorial

Source: Internet
Author: User
The PHP Group chat room fooking has been busy recently. The company has been coding and continues to fight at home. The more busy it is, the more difficult it is! I accidentally spent one night writing this group chat room. I just added the fooking websocket protocol two days ago to implement pure lua.

Fooking Project address:

Online demo address: http: // 182.254.135.131/chat/

In the development chat room, this is basically a general example of every socket persistent connection. it is easy to implement and can implement persistent communication between the client and the server using the least code. this is no exception this time, I still want to talk about things in the chat room, but this time I want to "advanced", so that I can Group it, instead of broadcasting a message to everyone. When a user sends data to a specified group, only the user in this group can receive the message, and other groups will not receive the message. Of course, the group here uses a fooking multicast mechanism to add N clients to a group (the group name can be any string ), when sending a message, you only need to specify the group name (that is, to store a list and traverse and send it, but this step is completed by fooking ).

The chat room interface is like this. the user list is on the left, the channel list is on the top right (you can select), and the message list is on the bottom, when you select a channel that you have not joined, the "Add to this channel" button will pop up. you can click it to join the channel. The rest is chat, and the general function is like this.


Such a chat room program requires less than 100 lines of php and less than 200 lines of html, css, and js. the configuration is also very simple, as shown in the following steps:

1. start the router, modify the router. lua configuration file (such as port and log) under the src Directory of the project, and then run:./fooking router. lua

2. start gateway and modify config in the src Directory of the project. the lua configuration file (such as the port, router port, script, and php program path, FASTCGI_ROOT), and then execute :. /fooking config. lua

Note: script. lua is configured in config. lua to handle packaging and package settlement. Note the path of script. lua when modifying config. lua.

Script. lua uses the websocket protocol. it depends on another Sha1.lua file (which is available in the src directory). Note that the script must be used. put lua and Sha1.lua in the same directory. Otherwise, an error may be reported.

3. install php-fpm, redis, and redis extension

4. modify the IP address and port of the websocket in the example/chat/index.html file (find ws: // to find it)

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.