preface

A few days ago a friend asked me about online chat, so I wrote a simple online chat system. Since I am using the latest version of Laravel, I need a version above PHP7.0 to build. For specific installation and use, please refer to GitHub.

GitHub Online experience

WebSocket

The web version of online chat is generally divided into two modes, polling and full duplex. In the traditional HTTP form, the Server cannot actively send messages to the Client, but in the full-duplex WebSocket form, the connection is kept long and the Server can actively push messages to the Client, which greatly saves the request resources. Swoole conveniently integrates these advanced features as extensions.

Train of thought

Create a user, create a room this very simple business logic will not repeat, here mainly talk about the implementation of chat. Since Swoole’s WebSocket is a separate PHP process, I use Redis for data sharing, use SET to complete the statistics of each room member, and use HASH to complete the binding of each Connect ID to the room number. For more information on how each type of Redis is used and how it works, see my previous article: Talk about Redis data structures. Swoole, I’m dealing with logic in command form, mainly in this article.

First post address: my blog

reference

How elegantly does Laravel use Swoole

This article was created by Nine under a Creative Commons Attribution 4.0 international license