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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools
