Features of Workerman

1. Pure PHP Development

Applications developed with Workerman can run independently without relying on containers like php-fpm, apache, or nginx. This makes it very convenient for PHP developers to develop, deploy, and debug applications.

2. Support for PHP Multi-Processes

To fully utilize the performance of multi-CPU servers, Workerman defaults to support multi-process and multi-tasking. Workerman starts one main process and several child processes to provide services externally. The main process is responsible for monitoring the child processes, while the child processes listen to network connections independently and receive, send, and process data. The simple process model makes Workerman more stable and efficient.

3. Support for TCP and UDP

Workerman supports both TCP and UDP transport layer protocols. You can switch the transport layer protocol by simply changing one property, with no changes needed in the business code.

4. Support for Long Connections

Many times, PHP applications need to maintain long connections with clients, such as in chat rooms and games. However, traditional PHP containers (apache, nginx, php-fpm) find it difficult to achieve this. With Workerman, as long as the server-side business does not actively call the close connection interface, PHP long connections can be used. A single Workerman process can support thousands of concurrent connections, while multiple processes can support hundreds of thousands or even millions of concurrent connections.

5. Support for Various Application Layer Protocols

Workerman's interface supports various application layer protocols, including custom protocols. Switching protocols in Workerman is also very simple; you only need to configure one field, and the protocol switches automatically with zero modifications to the business code. You can even open multiple ports for different protocols to meet different client needs.

6. Support for High Concurrency

Workerman supports the Libevent event polling library (which requires the event extension to be installed). Using Event under long connections and high concurrency showcases excellent performance. If the Event extension is not installed, it uses PHP's built-in Select-related system calls, which also perform powerfully.

7. Support for Smooth Service Restart

When a service needs to be restarted (for example, to release a new version), we do not want the processes handling user requests to be terminated immediately, nor do we want client communication to fail at the moment of restart. Workerman offers a smooth restart feature, ensuring service upgrades happen seamlessly without affecting client usage.

8. Support for File Update Detection and Auto-Loading

During the development process, we hope that our changes in code can take effect immediately so we can see the results. Workerman provides the FileMonitor Component. As long as there are updates to the file, Workerman will automatically run a reload to load the new file and make it effective.

9. Support for Running Child Processes as Specified Users

Since child processes are the ones actually handling user requests, for security reasons, child processes should not have high permissions. Therefore, Workerman supports setting the user under which child processes run, making your server more secure.

10. Support for Persistent Objects or Resources

During its operation, Workerman loads and parses a PHP file only once and then keeps it resident in memory. This means that class and function declarations, PHP execution environments, and symbol tables are not repeatedly created and destroyed, which is completely different from the PHP mechanism run under web containers. In Workerman, static members or global variables in the life cycle of a process are kept permanently unless actively destroyed, which means that objects or connections can be placed in global variables or class static members, allowing all requests during the life cycle of the current process to be reused. For example, as long as a database connection is initialized once within a single process, all requests for that process can reuse this database connection, avoiding the TCP three-way handshake, database permission verification, and the TCP four-way handshake when disconnecting that occur in a frequently connecting process, significantly improving application efficiency.

11. High Performance

Since PHP files are read from disk and parsed once, they remain in memory, allowing subsequent uses to directly utilize opcode in memory. This greatly reduces disk I/O as well as the overhead of initializing requests, creating execution environments, lexical parsing, syntax parsing, compiling opcode, and closing requests. Additionally, as it does not rely on containers like nginx or apache, it reduces the overhead of communication between nginx and PHP. Most importantly, resources can be kept permanently, eliminating the need to reinitialize database connections, resulting in very high performance for applications developed with Workerman.

12. Support for HHVM

Workerman supports running on the HHVM virtual machine, which can significantly enhance PHP performance. Especially in CPU-intensive operations, performance is outstanding. According to actual stress testing comparisons, Workerman exhibits a 30-80% improvement in network throughput when running under HHVM compared to running on Zend PHP 5.6 without load-bearing operations.

13. Support for Distributed Deployment

14. Support for Daemonization

15. Support for Multi-Port Listening

16. Support for Standard Input and Output Redirection