Home > Article > PHP Framework > How to develop worker cluster
GatewayWorker is based on a project framework developed by Workerman and is used to quickly develop TCP long connection applications, such as app push servers, instant IM servers, game servers, Internet of Things, smart homes, etc.
Workerman can be seen as a pure socket class library that can develop almost all network applications, whether it is TCP or UDP, long connection or short connection. Workerman has streamlined code, powerful functions, and flexible use, and can quickly develop various network applications. (Recommended learning: workerman tutorial )
(At the same time, workerman is also more at the bottom than GatewayWorker, and developers need a certain multi -process programming experience.
Tips
All interfaces provided by GatewayWorker support distributed calls, so the business code does not need any changes and can be directly deployed in a distributed manner.
How to distribute GatewayWorker
GatewayWorker uses the Register service to establish a divided cluster. The same cluster uses the same Register service IP and port , that is, the registration service addresses of Gateway and businessWorker ($gateway->registerAddress $businessworker->registerAddress) point to the same Register service.
Key steps in distributed deployment
1. A cluster only requires one server as the Register service, which is used to coordinate the establishment of Gateway and BusinessWorker when the process starts. To connect to communication, other servers can delete the start_register.php file or comment out the code inside.
(The Register service itself has very low communication volume and generally only communicates when the process is started, so the Register service itself will not become a bottleneck. Even if the Register service server temporarily hangs up during operation, it will not cause any impact on external network services. Impact, so the Register service generally does not need to be highly available)
2. Set the registration service address (registerAddress) of the Gateway and businessWorker to a unified Register service address, which is the server where the Register service selected in step 1 is located. ip and port.
3. Set the lanIp in the Gateway startup script (usually start_gateway.php) to be consistent with the current server intranet IP
The above is the detailed content of How to develop worker cluster. For more information, please follow other related articles on the PHP Chinese website!