PHP Websocket - Workerman

Created At: 2023-10-22 21:55:59 Updated At: 2023-10-22 21:59:42

Workerman, a high-performance PHP application container

What is Workerman?
Workerman is an open source, high-performance PHP application container developed purely in PHP.

Workerman is not reinventing the wheel. It is not an MVC framework, but a lower-level and more general service framework. You can use it to develop tcp agents, ladder agents, game servers, mail servers, ftp servers, and even develop a PHP version. redis, php version of database, php version of nginx, php version of php-fpm, etc. Workerman can be said to be an innovation in the field of PHP, allowing developers to completely get rid of the constraints that PHP can only do WEB.

In fact, Workerman is similar to a PHP version of nginx. The core is also multi-process + Epoll + non-blocking IO. Each Workerman process can maintain tens of thousands of concurrent connections. Because it is resident in memory, it does not rely on containers such as Apache, nginx, and php-fpm, and has ultra-high performance. It also supports TCP, UDP, UNIXSOCKET, long connections, Websocket, HTTP, WSS, HTTPS and other communication protocols as well as various custom protocols. It has many high-performance components such as timers, asynchronous socket clients, asynchronous Redis, asynchronous HTTP, and asynchronous message queues.

Some application directions of Workerman
Workerman is different from the traditional MVC framework. Workerman can not only be used for Web development, but also has a wider range of application fields, such as instant messaging, Internet of Things, games, service management, other servers or middleware, which undoubtedly greatly improves PHP development. the viewer’s vision. There is currently a shortage of PHP developers in these fields. If you want to have your own technical advantages in the PHP field, are not satisfied with the daily work of adding, deleting, modifying, and checking, or want to develop in the direction of an architect or a technical expert, Workerman is very worthwhile. A framework for learning. It is recommended that developers not only use it, but also develop their own open source projects based on Workerman to improve their skills and increase their influence. For example, the Beanbun multi-process web crawler framework is a good example, and it has received many praises shortly after it was launched.

Some application directions of Workerman are as follows:

1. Instant messaging
For example, web page instant chat, instant message push, WeChat applet, mobile app message push, PC software message push, etc.
[Example workerman-chat chat room, web message push, tadpole chat room]

2. Internet of Things
For example, Workerman communicates with printers, microcontrollers, smart bracelets, smart homes, shared bicycles, etc.
[Customer cases such as Yilianyun, Yibo Times, etc.]

3. Game server class
For example, board games, MMORPG games, etc. [Example browserquest-php]

4. HTTP service
For example, write high-performance HTTP interfaces and high-performance websites. If you want to create HTTP-related services or sites, webman is highly recommended.

5. SOA service-oriented
Use Workerman to encapsulate different functional units of existing business and provide a unified interface to the outside world in the form of services to achieve system loose coupling, easy maintenance, high availability, and easy scalability. [Example workerman-json-rpc, workerman-thrift]

6. Other server software
For example, GatewayWorker, PHPSocket.IO, http proxy, sock5 proxy, distributed communication component, distributed variable sharing component, message queue, DNS server, WebServer, CDN server, FTP server, etc.

7. Components
For example, asynchronous redis, asynchronous http client, Internet of Things mqtt client, message queue worker/redis-queue, worker/stomp, worker/rabbitmq, file monitoring components, and many component frameworks developed by third parties, etc.

Obviously it is difficult for the traditional mvc framework to achieve the above functions, so that is why Workerman was born.

Workerman concept
Minimalist, stable, high-performance, distributed.

Minimalist
Small is beautiful. The core of Workerman is extremely simple, with only a few php files and only a few interfaces exposed, making it very easy to learn. All other functionality is extended through components.

Workerman has complete documentation + authoritative homepage + active community + several QQ groups with thousands of people + numerous high-performance components + numerous examples, all of which make it easier for developers to use it.

Stablize
Workerman has been open source for several years and is used on a large scale by many listed companies. It is super stable. Some services have not been restarted for more than 2 years and are still running rapidly. No coredumps, no memory leaks, no bugs.

High performance
Because Workerman is resident in memory, it does not rely on apache/nginx/php-fpm. There is no communication overhead from the container to PHP, and there is no overhead of initializing everything and destroying everything with each request. It has ultra-high performance. Compared with the traditional MVC framework, The performance is dozens of times higher, and the QPS through ab stress test under PHP7 is even higher than that of nginx alone.

Distributed
Now is no longer the era of working alone. No matter how powerful a single server is, it has its limit. Distributed multi-server deployment is the way to go. Workerman directly provides a set of long-connection distributed communication solution GatewayWorker framework. Adding a server only requires simple configuration and startup. The business code has zero changes and the system carrying capacity is doubled. If you are developing a TCP long connection application, it is recommended to use GatewayWorker directly. It is a wrapper for Workerman and provides richer interfaces and powerful distributed processing capabilities for long connection applications.

Windows users (must read)
Workerman supports both linux and windows systems. The Windows version of Workerman itself does not rely on any extensions. You only need to configure the PHP environment variables. The installation and precautions of the Windows version of Workerman are required for Windows users.

Client
WorkerMan's communication protocol is open and customizable, so in theory WorkerMan can communicate with clients on any platform using any protocol. When the user develops the client, the communication with the server can be completed according to the corresponding communication protocol.

Comment

  • d
    dylan

    2024-01-06 07:46:35

    Hi Steinhaug, thanks for you comment. This is a great tool. we already have an working example of this. https://www.dbestech.com/tutorials/php-flutter-chat-a-marketplace-app Take a look. Thanks a lot.

  • s
    steinhaug

    2024-01-05 05:49:44

    Great article, really does explain alot. I would love to learn more, and it would be great to see a working example. Maby an idea for future article? Also the webman library, what is this and what is the usecase here ?

Add Reviews

Recommended Posts

Latest Posts

Subscribe our newsletter