How to Integrate with Other Frameworks
Question:
How to integrate with other MVC frameworks (such as thinkPHP, Yii, etc.)?
Answer:
It is suggested to integrate with other MVC frameworks as shown in the above diagram (using ThinkPHP as an example):
-
ThinkPHP and Workerman are two independent systems, deployed independently (can be deployed on different servers), and do not interfere with each other.
-
ThinkPHP provides web pages to be rendered and displayed in the browser using the HTTP protocol.
-
The JavaScript provided by ThinkPHP's pages initiates a websocket connection to connect to Workerman.
-
After the connection is established, a data packet (including a username, password, or some kind of token string) is sent to Workerman to authenticate which user the websocket connection belongs to.
-
Workerman's socket interface is only called to push data to the browser when ThinkPHP needs to push data.
-
Other requests are still processed using the original HTTP method in ThinkPHP.
Summary:
Workerman serves as a channel for pushing data to the browser, and its socket interface is only called when it is necessary to push data to the browser. All business logic is handled within ThinkPHP.
For how ThinkPHP can call the Workerman socket interface to push data, refer to the section "Push in Other Projects" in the FAQ.
ThinkPHP officially supports Workerman, please refer to the ThinkPHP 5 manual