Preface
Workerman, High-Performance PHP Application Container
What is Workerman?
Workerman is an open-source high-performance PHP application container developed in pure PHP.
Workerman does not reinvent the wheel; it is not an MVC framework, but rather a more low-level and general service framework. You can use it to develop TCP proxies, ladder proxies, game servers, mail servers, FTP servers, or even create a PHP version of Redis, a PHP version of a database, a PHP version of Nginx, a PHP version of PHP-FPM, and so on. Workerman can be considered an innovation in the PHP field, enabling developers to break free from the limitation of PHP being solely web-focused.
In fact, Workerman is similar to a PHP version of Nginx, utilizing multi-process + Epoll + non-blocking I/O at its core. Each Workerman process can maintain tens of thousands of concurrent connections. Since it resides in memory and does not rely on containers like Apache, Nginx, or PHP-FPM, it possesses extremely high performance. It supports TCP, UDP, UNIX SOCKET, long connections, and various communication protocols including Websocket, HTTP, WSS, and HTTPS, as well as various custom protocols. Workerman comes with many high-performance components such as timers, asynchronous socket clients, asynchronous Redis, asynchronous HTTP, and asynchronous message queues.
Some Application Directions of Workerman
Unlike traditional MVC frameworks, Workerman can be used not only for web development but also has broader application fields, such as instant messaging, Internet of Things, gaming, service governance, and other servers or middleware. This undoubtedly greatly broadens the horizons of PHP developers. Currently, there is a shortage of PHP developers in these fields. If you want to have your technological advantage in the PHP domain, are not satisfied with merely performing CRUD operations every day, or wish to develop towards an architect or technical expert direction, Workerman is a framework well worth learning. Developers are encouraged not only to use it but also to develop their own open-source projects based on Workerman, enhancing their skills and increasing their impact, like Beanbun Multithreaded Web Crawler Framework, which has received numerous positive reviews shortly after its launch.
Some application directions of Workerman include:
-
Instant Messaging
For example, web-based instant chat, instant message pushing, WeChat mini-programs, mobile app message pushing, PC software message pushing, etc.
[Example workerman-chat chat room, web message pushing, little tadpole chat room] -
Internet of Things
For example, communication with printers, communication with microcontrollers, smart bands, smart homes, shared bicycles, etc.
[Customer cases include Yilian Cloud, Yiparking Era, etc.] -
Game Server
For example, online board games, MMORPGs, etc.
[Example browserquest-php] -
HTTP Services
Such as writing high-performance HTTP interfaces and high-performance websites. If you want to develop HTTP-related services or sites, webman is strongly recommended. -
SOA Service
Use Workerman to encapsulate different functional units of existing businesses into a unified interface for external use, achieving loose coupling, maintainability, high availability, and scalability.
[Example workerman-json-rpc, workerman-thrift] -
Other Server Software
For example, GatewayWorker, PHPSocket.IO, HTTP proxy, SOCK5 proxy, distributed communication components, distributed variable sharing components, message queue, DNS servers, Web servers, CDN servers, FTP servers, etc. -
Components
Such as asynchronous Redis, asynchronous HTTP client, IoT MQTT client workerman/mqtt, message queues workerman/redis-queue, workerman/stomp, workerman/rabbitmq, file monitoring component, and many third-party developed component frameworks, etc.
Evidently, traditional MVC frameworks find it challenging to implement the above functionalities, which is precisely the reason for the birth of Workerman.
Workerman Philosophy
Minimalist, stable, high-performance, distributed.
Minimalist
Less is more; the Workerman core is minimal, consisting of only a few PHP files and exposing only a few interfaces, making it very easy to learn. All other functions are extended through components.
Workerman has comprehensive documentation, an authoritative homepage, an active community, several large QQ groups, a plethora of high-performance components, and numerous examples, all of which make it easier for developers to use.
Stable
Workerman has been open-sourced for several years and is widely used by many listed companies, proving to be super stable. Some services haven’t been restarted for over two years and are still running rapidly. There are no core dumps, no memory leaks, and no bugs.
High Performance
Workerman, as it resides in memory, does not depend on Apache/Nginx/PHP-FPM, thereby eliminating the communication overhead from containers to PHP, as well as the initialization and destruction overhead for each request, resulting in extremely high performance. Compared to traditional MVC frameworks, its performance is dozens of times higher, and under PHP7, the QPS recorded during ab performance testing even surpasses that of a standalone Nginx.
Distributed
We are no longer in the era of solitary development. Even the most robust single server has its limits. Distributed multi-server deployment is the way to go. Workerman provides a long-connection distributed communication solution called GatewayWorker framework, where adding servers requires simply configuring a few settings and starting them, with zero changes to the business code, thus exponentially increasing the system's carrying capacity. If you are developing TCP long-connection applications, it is recommended to use GatewayWorker, which is a wrapper around Workerman, providing richer interfaces and powerful distributed processing capabilities for long-connection applications.
Scope of This Manual
Workerman versions 3.x - 5.x
Windows Users (Must Read)
Workerman supports both Linux and Windows systems. The Windows version of Workerman does not rely on any extensions; it only requires properly configuring the PHP environment variables. For installation and notes regarding the Windows version of Workerman, please refer to Windows Users Must Read.
Client
The communication protocol of Workerman is open and customizable, thus theoretically allowing Workerman to communicate with clients from any platform using any protocol. When users develop clients, they can communicate with the server based on the corresponding communication protocol.