EasySwoole chat room code learning analysis

I took a look at the chat room code of easyswoole (hereafter referred to as es) in recent days. Because the es framework encapsulates swoole, some of the native methods of swoole are not used directly; in addition, I directly downloaded the code from github to win local, and did not install es on the linux server, so there is no in the code The core file of es brings some resistance to reading the code, but the problem is not big. This time I just learn the business process of the chat room. After installing es on linux, I will learn more about other functions.

First sort out the role of the project directory and files
Insert picture description here

1、EasySwooleEvent.php

From the framework life cycle diagram of the es document , you can see that after running the es service, es loads the configuration file, registers the default callback event, and starts to execute EasySwooleEvent.php. At this time swoole has not executed $server->start(); in the main file, you can register or overwrite events, or complete some initialization operations. Let's take a look at the code of this file.
Insert picture description here
In the process of reading the code, it is found that the class using the singleton mode does not define the getInstance method, but it can be instantiated directly using OnlineUser::getInstance()->…. This is because they quote a common trait: Singleton, as follows
Insert picture description here

Guess you like

Origin blog.csdn.net/u012830303/article/details/94720466