Home > PHP Framework > Workerman > body text

Features of WorkerMan

(*-*)浩
Release: 2019-11-26 14:22:47
Original
2313 people have browsed it

The following column of workerman php tutorial will introduce the features of WorkerMan to you. I hope it will be helpful to friends in need!

Features of WorkerMan

Features of WorkerMan

1. Pure PHP development

Applications developed using WorkerMan can run independently without relying on containers such as php-fpm, apache, and nginx. This makes it very convenient for PHP developers to develop, deploy, and debug applications.

2. Support PHP multi-process

In order to give full play to the performance of the server's multi-CPU, WorkerMan supports multi-process and multi-tasking by default. WorkerMan starts a main process and multiple sub-processes to provide external services. The main process is responsible for monitoring the sub-processes. The sub-processes independently monitor network connections and receive, send and process data. Due to the simple process model, WorkerMan is more stable and efficient.

3. Support TCP and UDP

WorkerMan supports TCP and UDP two transport layer protocols. You only need to change one attribute to change the transport layer protocol, and no business code is required. change.

4. Support long connections

Many times require PHP applications to maintain long connections with clients, such as chat rooms, games, etc., but traditional PHP containers ( apache, nginx, php-fpm) are difficult to do this. Using WorkerMan, as long as the server-side business does not actively call the connection closing interface, you can use PHP long connections. A single WorkerMan process can support tens of thousands of concurrent connections, and multiple processes can support hundreds of thousands or even millions of concurrent connections.

5. Support various application layer protocols

The WorkerMan interface supports various application layer protocols, including custom protocols. Changing the protocol in WorkerMan is also very simple. It only requires configuring a field, and the protocol is automatically switched without any changes to the business code. You can even open multiple ports with different protocols to meet different client needs.

6. Support high concurrency

WorkerMan supports the Libevent event polling library (the Libevent extension needs to be installed). The performance of using Libevent is very excellent in high concurrency. If it is not installed Libevent uses PHP's built-in Select-related system calls, and its performance is also very powerful.

7. Support smooth service restart

When the service needs to be restarted (such as a release version), we do not want the process that is processing the user request to be terminated immediately, let alone The moment you want to reboot cause client communication to fail. WorkerMan provides a smooth restart function to ensure smooth service upgrades without affecting the use of clients.

8. Support file update detection and automatic loading

During the development process, we hope that when we change the code, it will take effect immediately so that we can view the results. WorkerMan provides the FileMonitor file monitoring component. As long as the file is updated, WorkerMan will automatically run reload to load the new file and make it effective.

9. Support running child processes as specified users

Because the child process is the process that actually handles user requests, for security reasons, the child process cannot have too high permissions , so WorkerMan supports setting the user for the sub-running process to run, making your server more secure.

10. Support objects or resources to be maintained permanently

WorkerMan will only load and parse the PHP file once during the running process, and then it will reside in the memory, which makes the class and Function declarations, PHP execution environments, symbol tables, etc. will not be repeatedly created and destroyed, which is completely different from the PHP mechanism running under a web container.

In WorkerMan, static members or global variables are maintained permanently during the life cycle of a process without being actively destroyed. That is, if resources such as objects or connections are placed in global variables or class static members, All requests within the entire life cycle of the current process can be reused.

For example, as long as a database connection is initialized once in a single process, all subsequent requests of this process can reuse this database connection, avoiding the TCP three-way handshake, database permission verification, and disconnection during frequent database connections. The TCP four-way handshake process greatly improves application efficiency.

11. High performance

Since the php file is read and parsed from the disk once, it will be resident in the memory. The next time it is used, the opcode in the memory will be used directly, which is extremely It greatly reduces many time-consuming processes such as disk IO and PHP request initialization, creation of execution environment, lexical analysis, syntax analysis, compilation of opcode, request closing, etc. It does not rely on containers such as nginx and apache, and there is no need for nginx and other containers to communicate with PHP. The most important thing about the overhead is that the resources can be maintained permanently, and there is no need to initialize the database connection every time, so using WorkerMan to develop applications has very high performance.

12. Support HHVM

Support running on HHVM virtual machine, which can double the performance of PHP. Especially in CPU-intensive computing business, the performance is very excellent. Through actual stress test comparison, when there is no load business, the network throughput of WorkerMan running under HHVM is improved by about 30-80% compared to running under Zend PHP5.6

For more Workerman related technical articles, please visit the Workerman Tutorial column to learn!

The above is the detailed content of Features of WorkerMan. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template