Home >PHP Framework >Swoole >Is swoole an extension of php?

Is swoole an extension of php?

(*-*)浩
(*-*)浩Original
2019-12-09 09:55:132521browse

Is swoole an extension of php?

Swoole is written in C language and runs as a PHP extension. Swoole's network IO part is based on the epoll/kqueue event loop and is fully asynchronous and non-blocking. The business logic part uses multi-process synchronous blocking mode to run.

This ensures that the Server can handle high concurrency and a large number of TCP connections. It also ensures that business code can still be written simply. (Recommended learning: swoole video tutorial)

Advantages of Swoole over Node.js

1. Swoole natively supports multi-process/multi-threading

Developers only need to modify one parameter and configure how many processes to start. The Node.js network library itself does not provide multi-process/multi-thread implementation. Developers need to create the process themselves. Or simply use single threading. This does not take full advantage of multiple cores.

2. Swoole uses message passing and multi-Worker processes instead of multi-thread shared memory locking. Although the performance of shared memory is very good, there are security issues and locks need to be locked when reading and writing. Excessive lock granularity will result in only one thread running. If the lock is too complex, there will be deadlock problems. So developers need to be very careful.

3. The code of swoole is written synchronously instead of nested asynchronous callbacks

If the code of Node.js is too complex, it will nest multiple layers of callbacks, so that The code loses readability and the program flow becomes messy. Swoole uses the traditional semi-synchronous and semi-asynchronous multi-Worker implementation method under Linux. Business code is written in a synchronous manner, which is simpler.

Swoole also has a built-in implementation of the Socket client, but it is executed in a synchronous and parallel manner. PHP itself also provides socket functions, but some functions have some bugs and are relatively complex. Swoole's built-in client classes are more secure and simplified.

4. swoole has built-in additional features that Node.js does not have

such as CPU

Affinity settings, daemon process ization, mixed UDP/TCP multi-port monitoring, multi-timers, etc.

The above is the detailed content of Is swoole an extension of php?. For more information, please follow other related articles on the PHP Chinese website!

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
Previous article:Why is swoole efficient?Next article:Why is swoole efficient?