Home >headlines >Who has better performance, workerman or swoole? how to choose?

Who has better performance, workerman or swoole? how to choose?

青灯夜游
青灯夜游Original
2022-12-01 10:00:375821browse

Who has better performance, workerman or swoole? how to choose?

workerman Compared with swoole, which one would you choose in actual development projects? Do you have any advice on which one is better for newbies to learn?

There are comments on the Internet that the performance of Swoole is much higher than that of Workerman. Is this true?

Let’s take a look at their respective introductions first:

workerman: Open source high-performance PHP application container (github 10.2k )

Who has better performance, workerman or swoole? how to choose?

workerman is a network framework written in pure PHP, supporting high concurrency and ultra-high stability. It greatly breaks through the traditional PHP application scope and is widely used for instant messaging. , APP development, small program development, chat rooms, mobile game servers, online games, hardware communications, Internet of Vehicles, smart homes, Internet of Things and other fields. [workerman Tutorial]

Supports TCP long connection, supports Websocket, HTTP and other protocols, supports custom protocols, has asynchronous Mysql, asynchronous Redis, asynchronous Http, MQTT IoT client, asynchronous Message queue and many other high-performance components.

Swoole: PHP coroutine framework (github 17.6k)

Who has better performance, workerman or swoole? how to choose?

Swoole is a network communication extension written in c/c, Swoole It enables PHP developers to write high-performance and high-concurrency TCP, UDP, Unix Socket, HTTP, WebSocket and other services, so that PHP is no longer limited to the Web field.

Swoole can be widely used in the Internet, mobile communications, cloud computing, online games, Internet of Things (IOT), Internet of Vehicles, smart homes and other fields. Using PHP Swoole can greatly improve the efficiency of enterprise IT R&D teams and focus more on developing innovative products.

The functions of the two are similar

So which one is better? How should we choose?

Let’s listen to the experience and opinions of using PHPer

1: Learning cost

First of all, let’s explain the views of php Chinese website:

For novices, we are more inclined to recommend Workerman: simple, easy to use, good scalability, and can get started quickly! Isn't the value of the PHP language simple and easy to use?

Currently there are very few latest courses on Workerman on the entire Internet, so the PHP Chinese website has recently carefully recorded a set: PHP Workerman Basics to Practical Courses, launched today!

Hope it can help students improve their skills!

Course name:

PHP Workerman ThinkPHP6 Instant Messaging Chat System

Who has better performance, workerman or swoole? how to choose?
(ThinkPHP6 Workerman/websocket)

This course is based on the real-time web chat system developed by php workererman to create websocket service. The course content mainly includes:

1 , websoket communication principle and relationship with http

2. Workerman builds websoket service

3. QQ group chat principle and implementation

4. Workerman message push and timer

5. One-on-one private chat and random assignment by customer service

6. Customer service background obtains online customer list, etc.

7. Chat message storage and other contents.

Who has better performance, workerman or swoole? how to choose?

Interested students, hurry up and get on the bus to lock in the new event price!

Limited time discount activity:
Original price ¥399 yuan, limited time discount price ¥189 Yuan, ends on December 8th!

All courses are expected to be updated before December 8th, and the prices will be increased by then!

Open address↓↓↓
https://www.php.cn/course/1475.html

Who has better performance, workerman or swoole? how to choose?
Course consultation courseware materials collection

Netizens’ opinions:

Netizens’ evaluation 1:

If you have no previous experience in network programming or multi-process development, my suggestion is that you start with Workerman. After all, Workerman is implemented in pure PHP code. You will not have too much trouble understanding its principles and handling problems in depth. big obstacle.

Through in-depth study of Workerman, you can learn the basic knowledge related to network programming, how this kind of program is designed and implemented, and what details need to be paid attention to. You can also learn how to develop multi-process programs and how to manage and communicate between processes.

After you understand these clearly, you will feel that the threshold is not so high when you transition to swoole. If you start using swoole directly, at least the management and communication between processes need to be implemented by yourself, and you may not even There are no ideas.

From the shallower to the deeper, start with the basics and then advance to the advanced level.

Netizen evaluation 2:

swoole is an extension of PHP and does not rely on other extensions. The bottom layer is C and can be called directly in the program. It has good performance. higher. Workman uses native PHP and relies on other extensions, so you need to download the source code package.

The former can be understood as swoole is an api provided to php. It is relatively native, so it does not encapsulate the business logic in practice and needs to be developed by yourself. The latter encapsulates certain business needs and is easier to get started.

I have been learning swoole for a few months. I find it difficult to control. It requires more basic knowledge and is rarely used in actual work, but I feel it is worth learning.

In short, which one to use depends on what it is used for and public demand. Workman may have lower development costs. For some specific needs, you can also study swoole.

Netizen evaluation 3:

Recommend workerman! Swoole's set of direct C expansion is not suitable for advanced novices. What novices want is gradual, stable and step-by-step. First master a paradigm and then proceed step by step.

workerman has also released the official web framework webman, and its stress test ranking is higher than swoole. It is no exaggeration to say that workerman is currently the most mature and lowest-cost PHP solution, and the threshold is still low.

Netizen evaluation 4:

swoole is a PHP extension class developed in C language. In terms of performance, swoole has advantages and is very suitable for PHP programs. There are certain requirements for developers to understand the development of underlying communication services, which requires a lot of knowledge. Swoole is generally suitable for experienced developers. Workerman is a pure PHP development framework that is easy to get started with. It is said that as long as you know PHP, you can use it to develop socket application services.

It is recommended to learn workerman first, and then learn swoole.

Netizen evaluation 5:

workerman is a pure PHP-implemented resident memory framework, synchronous blocking mode, learn this first to facilitate the resident Have a certain understanding of memory patterns and a certain understanding of memory leaks.

Workerman will learn swoole after getting familiar with it. In addition to resident memory, swoole also has coroutines, which does not exist in the traditional development model. Coroutines are similar to threads. During the development process, it is necessary to focus on the operation issues between the data in each coroutine.

2: Practical application

Netizen evaluation 1:

One of my open source projects uses the Workerman project view, which relies on fewer environments and is less difficult to develop. If there are not tens of thousands of concurrent requests, workerman is recommended. But my experience shows that 95% of projects will not have tens of thousands of concurrency. For beginners, I also recommend using workerman. You can also learn swoole at the same time. After all, coroutines save hardware resources. Also, the author of workerman is super patient in answering various questions. I have never seen such enthusiastic

Netizen comment 2:

swoole It is an extension. While using Workerman, if you need to use swoole, you can also use it. And from an application perspective, I prefer Workerman Gateworker. These can directly solve many problems and avoid basic research.

Netizen evaluation 3:

workerman is simpler and more stable. I still use it after considering it for a long time. Workerman, swoole is too messy at the moment. The production environment is stable. After all, the native PHP tool swoole has been playing for a while and has too many pitfalls.

Netizen comment 4:

I struggled with the deployment of Swoole for a week, and finally I was able to get it through. Thinking about it again, there are still many steps. If we have to continue to struggle with third-party libraries and extensions, forget it.

Gatewayworker directly uses the XFTP tool to drag the folder in and then start, which saves a lot of worry.

For a novice like me, regardless of clusters, tens of millions of concurrencies, or containers, I choose Gatewaywroker.

Netizen evaluation 5:

Personally, I think both swoole and workerman can solve high-concurrency io problems, but they use two ideas. There is no one who is superior or inferior. Writing PHP extensions in C to solve problems seems so awesome, but that’s not necessarily the case. When writing PHP extensions in C, the comparison should be made by C programmers, not PHP programmers. Then C language is more advanced than PHP language. In that case, everyone can use C to develop websites.

New course recommendation:

Who has better performance, workerman or swoole? how to choose?

##三: Performance

Netizen evaluation 1:

The reason why swoole is better than workerman is because the commenter has never used it. Workerman, he only one-sidedly believes that C is faster than PHP, and thinks that the same is true for its program framework.

However, Workerman only loads and parses the PHP file once, and then resides in the memory, which greatly reduces disk IO and request initialization, creation of execution environment, lexical analysis, syntax analysis, compilation of opcode, and requests in PHP Closing and many other time-consuming processes. So purely from a language level comparison, it should be the difference between c and machine code.

Both are very excellent open source frameworks, it just depends on whether you prefer c or php

Netizen evaluation 2:

In fact, the performance is almost the same. Workerman is more stable, can find problems, and is easier to maintain.

Netizen evaluation 3:

From the running scores, every Each indicator, Workerman, is slightly higher than that of Swoole. Overall, the results of Swoole and Workerman are similar, but this is just a running score. The real effect still depends on the actual project.

Netizen comment 4:

I think they are all wrong. Comparing both sides

workman is written in PHP. But the essence is to use pcntl and other extensions to implement the function

swoole is written in C/C, but it actually appears in the form of a PHP extension

So it is actually a PHP extension

So it actually compares the performance of extensions such as pcntl and swoole extensions

So isn’t it normal that workman is not slow?

Netizen evaluation 5:

https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=db&l =zik073-1r

This is the 19th round of stress testing of the authoritative foreign stress testing agency www.techempower.com, with database business. Swoole uses the database connection pool coroutine, and workererman is the original PHP mysql blocking usage. The conclusion is still that there is not much difference in performance between the two. Workerman is better in all performance indicators, especially plaintext, which is about 35% higher than swoole. Of course, this is just the stress test result, which has only partial reference significance and does not represent the final result of the actual project.

New course recommendation:

Who has better performance, workerman or swoole? how to choose?

##four :Ecology

Netizen evaluation 1:Because of the needs of the project, such as smart home, I originally planned to use C Do it. Think about it. Swoole and Workerman are very popular and mature, and have many stable application scenarios. Think about it, why can't you try it with these two? C level is limited, how good can it be to use PHP to meet the needs?

So today I have a general understanding of swoole and workerman. My initial impression of swoole is not as good as I imagined. On the contrary, workerman makes me very surprised...

Let’s talk about swoole first:

swoole, the manual at the top of the official website is actually I couldn't open it, so I searched for a long time and found a manual. Why can't your nb team make the official website more decent? Does it require a lot of work? Can you at least change the manual at the top of the official website to the correct address? If you encounter a problem, you can find it. I haven't found any solution in the circle. I posted issues and forums, but there was no response...

Let's talk about workererman:

workerman's examples are very complete and the explanations are detailed, much better than swoole. The important point is that such high performance can be achieved with pure PHP. php-cli has been mature in the php5.3 era. I have never had time to do large-scale projects based on this. I always feel that the performance is not good, but Workerman surprised me.

The pcntl and posix extensions used by Workerman are also PHP's own extensions and will be compiled in by default. The streams series of functions are PHP's own functions and there is no extension. So what someone said is too exaggerated. And There is no need for immature third-party extensions. These two extensions are very mature extensions and are stable enough to be enabled by default in PHP. Streams even enters the basic functions of PHP. If you want to enable Kqueue and Epoll like Nginx, you need to install it like swoole. The pecl extension: pecl-event. This extension is also very stable. These are basic extensions and will not be unstable and will not be supported by PHP7 or PHP8. streams, pcntl, posix, and pecl-event are actually shallow encapsulation of the underlying layer. There is no problem with the performance. It depends on how you use it and whether you can use it. Workerman is very good at using it.

Finally:

I don’t agree with what Han Tianfeng said about swoole needing to be at a higher level. In fact, both are packaged for you and can be used. But if there is a problem, Workerman can go Understand the protocol and modify the encapsulated PHP code. Swoole cannot modify it. At least you need to know C language to modify it. This is something that many phpers are not good at.

I decided to use workerman for the time being, because of the above I can solve that kind of problem by modifying Workerman's PHP code myself. However, swoole is re-implemented in C. There are many pitfalls to improve, and the community is not active, no one cares about it, and I don't have the energy to check the C code to find the reason. Found Many people also tried swoole and found that workerman is more stable, so they switched to workerman. In fact, I still hope that swoole can develop quickly and improve.

The above is purely a personal opinion, everything is for the health of PHP With rapid development, I hope swoole will get better and better...

Netizen comment 2:

In fact, they are almost the same. If it is directly based on swoole or Workerman development is not easy.

But now they can all be developed based on frameworks, such as hyperf and webman. Of course, if you also try imi, you will find that there is basically no difference when using them.

Imi said, I support it anyway!

Netizen comment 3:

Workerman’s documentation is very good and has many examples. I think Workerman is easier to get started with, and it is easier to use than Workerman. swoole is very stable

Netizen evaluation 4:

Official solution fpm opcache jit long connection, or workererman, as stable as an old dog, official solution, Solve problems easily by yourself.

There is really no way to introduce third-party language synthesis. If you are concerned about PHP's official coroutines or asynchronous solutions, you can browse the Fiber extension launched by the author of Amphp, which has entered the rfc stage.

Netizen evaluation 5:

workerman is more in line with the spirit of PHP. As a Workerman user for more than a year, I firmly support Workerman. Moreover, the workers are really serious. They respond to novice questions in the forum in a timely manner and are extremely friendly to novices.

Recommended quality courses:

1. ThinkPHP version : "PHP Workerman Basics and Practical Combat: Instant Communication Chat System (Latest online on 2022.11.30)

Who has better performance, workerman or swoole? how to choose?
(original price ¥399 yuan, new discount Price ¥189 yuan, only for 8 days)

Opening address↓↓↓
https://www.php.cn/course/1475. html

##2. Laravel version: Based on workerman imitating Baidu Shangqiao IM instant messaging (Laravel actual combat) (online on 2020.10.12 )

Who has better performance, workerman or swoole? how to choose?(original price ¥299 yuan,
limited time discount price ¥139 yuan, only for 8 days)

Open address↓↓↓
https://www.php.cn/course/1131.html

Who has better performance, workerman or swoole? how to choose?
Course consultation courseware materials collection)

Do you agree with the above views of PHPer? Experts are welcome to spray!

Statement:
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