How to Integrate with Other Frameworks

Q:

How to integrate with other MVC frameworks (such as ThinkPHP, Yii, etc.)?

A:

workerman-thinkphp

Recommendation for integrating with other MVC frameworks (using ThinkPHP as an example):

  1. ThinkPHP and Workerman are two independent systems that can be deployed independently (they can be on different servers) and do not interfere with each other.

  2. ThinkPHP provides web pages to be rendered and displayed in the browser using the HTTP protocol.

  3. The JavaScript on the page provided by ThinkPHP initiates a WebSocket connection to Workerman.

  4. Once connected, it sends a data packet to Workerman (containing the username, password, or some token string) to verify which user the WebSocket connection belongs to.

  5. Only when ThinkPHP needs to push data to the browser should it call Workerman's socket interface to perform the push.

  6. All other requests should still be processed using the original ThinkPHP HTTP method.

Summary:

Treat Workerman as a channel for pushing data to the browser, calling the Workerman interface only when it is necessary to push data to the browser. All business logic is handled entirely within ThinkPHP.

For how ThinkPHP calls Workerman's socket interface to push data, refer to see FAQ - Pushing in Other Projects.

ThinkPHP officially supports Workerman; see ThinkPHP5 Manual