PHP Group chat room fooking Reality

Source: Internet
Author: User
Recently also relatively busy, the company dozen yards, go home to continue to play, the more busy the more toss! One careless midnight, spent a night to finally put this group chat room finished, the first two days just put fooking websocket protocol Plus, pure LUA implementation.

Fooking's Project Address:

Online Demo Address: http://182.254.135.131/chat/

Development Chat Room This is basically on each socket long connection of a general rule, mainly to achieve simple, can use the least code to achieve the client and the service end of the persistent communication, then this time is no exception, or take chat room to say things, but this time to "advanced" point, can group, rather than send a message broadcast to everyone. When a user sends data to a specified group, only the users in this group can receive the message, and the other group does not receive the message. Of course, the grouping here is the use of a fooking multicast mechanism, to add N clients to a group (the group name can be any string), when sending a message only need to specify the group name (in fact, it is to store a list, and then traverse the send, but this step is done by fooking).

Chat room interface is like this, the left is the user list, the top right is the channel list (you can choose), the following is a list of messages, when you choose a channel you have not joined will pop up "Join this Channel" button, click to join the channel, the rest is to chat, the general function is such a son.


Such a chat room program, only need less than 100 lines of PHP and less than 200 lines html/css/js, its configuration is very simple, the following steps:

1, start router, modify the project src directory Router.lua configuration file (such as: port, log, etc.), and then execute:./fooking Router.lua

2, start the gateway, modify the project src directory Config.lua configuration file (such as: port, router port, script, PHP program path, etc., the most important is fastcgi_root), and then perform:./fooking Config.lua

Note: Script.lua is configured in Config.lua (for handling package and unpacking), please note the path of Script.lua when modifying Config.lua

Script.lua Use the WebSocket protocol, he needs to rely on another Sha1.lua file (in the SRC directory), please note that you must put Script.lua and Sha1.lua in the same directory, or may error

3. Install PHP-FPM, Redis, Redis extension

4, modify the example/chat/index.html file inside the WebSocket IP and port (find ws://can find)

  • 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.