What’s New in Swoole v6.0? Multithreading, Coroutines, and Async I/O for PHP
Swoole v6.0 introduces multithreaded coroutine support, async file I/O via io_uring, new thread‑related classes, upgraded Boost Context, numerous bug fixes and kernel optimizations, expanding PHP’s capabilities beyond traditional web workloads to high‑performance networking, game servers, and micro‑services.
Overview
Swooleis a C++‑based asynchronous event‑driven and coroutine network engine that provides high‑performance networking support for PHP. It offers TCP/UDP, high‑performance Web, WebSocket, IoT, real‑time communication, game, and micro‑service servers, allowing PHP to move beyond traditional web scenarios.
After months of development and testing, the first release of Swoole v6 has been published.
Swoole v6.0
The Swoole v6 release adds a multithreaded + coroutine programming model. Developers can enjoy the convenience of coroutine‑based I/O while also leveraging true multithreaded parallel execution and shared memory stacks, making PHP more efficient for game and communication servers.
Swoole v6.0 aims to provide a stable, production‑ready multithreading solution for PHP and invites users to try it and submit test reports and feedback.
New Features
Multithread mode is available when PHP runs in zts mode; enable it at compile time with --enable-swoole-thread.
Added thread management class Swoole\Thread.
Added thread lock class Swoole\Thread\Lock.
Added atomic counters Swoole\Thread\Atomic and Swoole\Thread\Atomic\Long.
Added safe concurrent containers: Swoole\Thread\Map, Swoole\Thread\ArrayList, Swoole\Thread\Queue.
Async file operations powered by iouring (requires liburing and compile with --enable-iouring) now support functions such as file_get_contents, file_put_contents, fopen, fclose, fread, fwrite, mkdir, unlink, fsync, fdatasync, rename, fstat, lstat, and filesize.
Boost Context upgraded to version 1.84, enabling coroutine support on Loongson CPUs.
Example Code
Creating a thread: use Swoole\Thread; Thread + Server (asynchronous style): use Swoole\Process; Thread + Coroutine inside a thread: use Swoole\Thread; Concurrent Map:
use Swoole\Thread;Bug Fixes
Fixed inability to install via pecl.
Fixed Swoole\Coroutine\FastCGI\Client unable to set keep‑alive.
Fixed errors when request parameters exceed max_input_vars, causing process restarts.
Fixed unknown issue caused by Swoole\Event::wait() in coroutines.
Fixed proc_open not supporting PTY in coroutine mode.
Fixed segmentation fault of pdo_sqlite on PHP 8.3.
Removed useless warnings when compiling Swoole.
Handled errors when STDOUT/STDERR are closed and zend_fetch_resource2_ex is called.
Fixed invalid set_tcp_nodelay configuration.
Resolved occasional unreachable branch during file uploads.
Fixed errors caused by setting dispatch_func.
Fixed deprecation of AC_PROG_CC_C99 in autoconf ≥ 2.70.
Added exception handling when thread creation fails.
Fixed undefined _tsrm_ls_cache issue.
Fixed fatal compile errors with GCC 14.
Kernel Optimizations
Removed unnecessary checks on socket structs.
Upgraded the Swoole library.
Added support for HTTP 451 status code in Swoole\Http\Response.
Synchronized file operation code across different PHP versions.
Synchronized PDO operation code across different PHP versions.
Optimized Socket::ssl_recv() implementation.
Improved config.m4 so dependencies can be set via pkg-config.
Optimized request‑header parsing by using dynamic arrays.
Fixed file‑descriptor lifecycle issues in multithreaded mode.
Optimized several coroutine core logics.
Deprecations
Support for PHP 8.0 has been dropped.
The coroutine clients Swoole\Coroutine\MySQL, Swoole\Coroutine\Redis, and Swoole\Coroutine\PostgreSQL are no longer supported.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
