Home >PHP Framework >Swoole >The difference between swoole versions

The difference between swoole versions

(*-*)浩
(*-*)浩Original
2019-12-16 11:39:213379browse

The difference between swoole versions

The official version of Swoole 2.0 is released. The biggest update in version 2.0 is the addition of support for coroutines. The official version supports both PHP5 and PHP7.

Based on the Swoole2.0 coroutine, PHP developers can write code in a synchronous manner, and the underlying layer automatically schedules the coroutine and transforms it into asynchronous IO. Solve the problem of nested callbacks in traditional asynchronous programming. (Recommended learning: swoole video tutorial)

Compared with the implementation of yield/generator and async/await in Node.js (ES6), Python and other languages, Swoole coroutine does not need to be modified. The code adds additional keywords.

Compared with goroutine in Go language, Swoole coroutine is built-in. The application layer code does not need to add the go keyword to start the coroutine. It only needs to use the encapsulated coroutine client, which is simpler to use. . In addition, the IO component of the Swoole coroutine has a built-in timeout mechanism at the bottom layer, so there is no need to use complex select/chan/timer to implement client timeout.

Currently, the built-in coroutine client components at the bottom of Swoole include: udpclient, tcpclient, httpclient, redisclient, and mysqlclient, which basically cover several communication protocols commonly used by developers. Coroutine components can only be used in the server's onConnect, onRequest, onReceive, and onMessage callback functions.

In Swoole version 3.0, we have implemented a brand new PHP built-in coroutine scheduler, based on ZendVM's EG (vm_interrupt) mechanism, removing the dependency on setjmp/longjmp.

enables the Swoole coroutine to be applied anywhere, including PHP object destructors, magic methods, reflection function calls and other scenarios. The new version number will be changed to Swoole 3.0. The original plan was to be based on libco C stack coroutine, postponed to 4.0.

The new version of the coroutine kernel relies on PHP-7.1, so Swoole's dependence on PHP version has been increased to 7.1, and its dependence on gcc version has been increased to 4.8.

Swoole 4.0 implements a new coroutine kernel based on boost.context 1.60assembly code.

On the basis of saving the PHP function call stack, the context storage of the C stack is added. Implemented support for all PHP syntax. Coroutines can now be used in any PHP function, including call_user_func, reflection, magic method, and array_map.

4.0 is 100% compatible with 2.0, only the coroutine kernel has been reconstructed, and the API layer has not changed

The 4.0 branch code will be upgraded to the C 11 standard. It is recommended to use gcc-4.8 or more High version

Supports php7.1 and above

The above is the detailed content of The difference between swoole versions. 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:How to apply swoole_mysqlNext article:How to apply swoole_mysql