swoole

Event-driven asynchronous and concurrent networking engine with high performance for PHP.


Event-driven asynchronous and concurrent networking engine with high performance for PHP.
- event-driven
- coroutine
- asynchronous non-blocking
- multi-thread reactor
- multi-process worker
- multi-protocol
- millisecond timer
- built-in tcp/http/websocket/http2 server
- coroutine tcp/http/websocket client
- coroutine mysql client
- coroutine redis client
- coroutine read/write file system
- coroutine dns lookup
- support IPv4/IPv6/UnixSocket/TCP/UDP
- support SSL/TLS encrypted transmission

License: Apache2.0

Latest releases

Version Release Download
6.1.0RC1 2025-08-30 swoole-6.1.0RC1.tgz
6.0.2 2025-03-22 swoole-6.0.2.tgz
6.0.1 2025-02-14 swoole-6.0.1.tgz
6.0.0 2024-12-16 swoole-6.0.0.tgz
6.0.0RC1 2024-11-22 swoole-6.0.0RC1.tgz
Show all releases

Changelog

Version Message
6.1.0RC1 ## **Standard Library Extension**

In version `6.1`, `Swoole-Cli` will introduce extended syntax for the `PHP` standard library, providing additional new syntax while maintaining full compatibility with the official `PHP` syntax. These new extended syntax features are entirely optional and do not affect existing `PHP` code. The standard library extension syntax will be implemented in the `stdext` module of `ext-swoole`.

- `swoole-cli` users can use it directly without any additional parameters.
- `ext-swoole` users need to add `--enable-swoole-stdext` during compilation to enable it.
- `stdext` can be used in `php-cli`, `php-fpm`, `cli-http-server`, and `swoole` modes.

### **1. Object-Oriented Basic Types**

Version `6.1` implements object-oriented encapsulation of basic types such as `array`, `string`, and `stream`, supporting method calls in an object-oriented style. Built-in methods can be directly called on variables of these types.

The built-in methods for basic types still utilize the `PHP` standard library. These methods correspond one-to-one with `PHP`'s `str_` or `array_` series functions. For example, `$text->replace()` corresponds to the `str_replace` function. The underlying implementation only adjusts function names, slightly modifies the parameter order for a few methods, and adjusts parameter and return value types for several others. For details, please refer to the [Swoole Documentation](https://wiki.swoole.com/).

### **2. Typed-Array**

Typed arrays can enforce type constraints, such as `Map` or `ArrayList`, and restrict the types of keys and values. Multi-level nested formats are supported. Typed arrays are still essentially `array` types, with parameter checks performed only during write operations. Typed arrays can be passed as `array` to other functions or class methods.

## **New Features**
- **Default llHTTP Parser**: Starting from v6.1.0, Swoole uses the higher-performance `llhttp` as the default HTTP message parser, replacing `http_parser`.
- **Coroutine-Based File Download**: `Swoole\Coroutine\Http\Client` now supports full coroutine-based file download operations.
- **Asynchronous File Truncation**: Added support for `iouring ftruncate`, expanding asynchronous file operation capabilities.

## **Bug Fixes**
- **Thread Mode Optimization**:
- Fixed the issue where `hook_flags` settings were ineffective in `SWOOLE_THREAD` mode.
- Fixed the issue where heartbeat threads held invalid pointers and accessed freed memory after worker threads restarted due to reaching the `max_request` limit.
- Fixed the issue where `Task` processes could not be restarted individually.
- **Stability Improvements**:
- Fixed the issue where synchronous processes (including manager and task processes) could not use `process::signal()` properly.
- Corrected the resource cleanup mechanism when worker processes exit abnormally.
- Resolved compilation failures on the Cygwin platform.
- Fixed the issue where curl could not reuse sockets when keepalive was enabled.
- Improved the logging component to address data consistency issues in multi-threaded mode.
- Fixed compilation failures of the `futex` feature in `io_uring` on `ubuntu24.04`.
- Fixed compilation failures caused by struct sequential assignment on older Linux systems.
- Fixed the issue where the `id` property of directly instantiated `Swoole\Process` objects was uninitialized.
- Fixed the missing zstd option in composer.json when compiling Swoole with PIE.
- **Compatibility Improvements**:
- Fixed compatibility issues with `php_swoole_register_shutdown_function` on PHP 8.5.
- Corrected the handling of null parameters in `Swoole\Table::get()`.
- **Protocol Handling**:
- Optimized the handling of duplicate fields in HTTP request and response headers to ensure proper merging.
- Fixed the issue where a warning about an unknown compression method was triggered when processing client `Accept-Encoding: zlib` headers without `zlib` installed.

## Deprecations
- Support for the `select` event mechanism has been removed. `select` only supports event monitoring for up to `1024` handles and has significant limitations. On platforms that do not support `epoll/kqueue`, `poll` will be used as the event polling mechanism, enabling support for high concurrency even on the `Cygwin` platform.
- The second parameter `$waitEvent` in `Swoole\Server::stop()` has been deprecated. Please use the `reload_async` parameter instead.

## **Architectural Optimizations**

Version `6.1` adds extensive unit tests for core modules, increasing test coverage to **86%**. By systematically supplementing test cases and refactoring underlying code logic, combined with full static code analysis using the `clang-tidy` toolchain, automated code formatting and redundancy cleanup have been achieved, significantly improving code readability and maintainability.

- Optimized the underlying `SSL` module.
- Optimized the underlying `Socket` module.
- Refactored the underlying synchronous signal module.
- Refactored the underlying `reactor` and `string` modules.
- Refactored the underlying dynamic log file reloading mechanism based on `SIGRTMIN` signals.
- Optimized the underlying static file server by removing C-style code and unifying it into C++-style code.
- Optimized thread initialization logic to improve multi-threaded performance. Memory for independent management structures is now managed separately, eliminating the need for locks during thread creation and exit.
- Removed the `socket_dontwait` option from the underlying `async` module, as it is deprecated.
- Improved test coverage for `WebSocket` mask handling.
- Optimized the `sendfile` functionality to avoid setting the `tcp_cork` option for files smaller than `64KB`.
- Added unit tests for `aarch64` and `macOS` environments.
- Optimized underlying client network address resolution and settings.
- Added `ssl_cafile/ssl_capath` configuration items for the `Server` module.
- Added the `print_backtrace_on_error` configuration, which prints C function stack traces when location errors occur.
- Added the `Address Sanitizer` debugging tool.
- Added `Cygwin` testing, significantly improving compatibility and stability on the `Cygwin` platform.
- On `macOS` systems, the `kqueue` event mechanism does not support cross-process pipe event monitoring, making it impossible to use `SWOOLE_PROCESS` mode and `Task` processes. Therefore, the system defaults to using `poll` as the underlying event mechanism. To enable `kqueue`, manually activate it using `Swoole\Server::set(['enable_kqueue' => true])` and `swoole_async_set(['enable_kqueue' => true])`.

## **Note**
- This version is an `RC` (Release Candidate) and not an official release. It is recommended for use only in testing environments and should not be used in production.

## **Acknowledgments**
Sincere thanks to @matyhtf @jingjingxyk @sy-records @KIMDONGYEON00 @ServBayDev @NathanFreeman and all contributors for their professional efforts. Swoole is stronger because of you! Wishing all open-source community partners good health, success in all endeavors, and smooth work.
6.0.2 - Added `Swoole\Thread::yield()`, `Swoole\Thread::activeCount()`, and `Swoole\Thread::isAlive()` methods. @matyhtf
- Fixed an issue where using single-thread mode and setting heartbeat in `SWOOLE_THREAD` mode would cause exceptions. @matyhtf
- Fixed a segmentation fault issue after enabling `swoole.enable_fiber_mock`. @NathanFreeman
- Fixed an integer overflow issue in the Redis server. @yannaingtun
- The Redis server currently only supports the `RESP2` protocol. When formatting strings that do not comply with this protocol, an exception will be thrown instead of logging. @matyhtf
6.0.1 - Fixed an issue in `SWOOLE_THREAD` mode where the process could not exit properly due to not removing the listening event. @NathanFreeman
- Fixed an issue where large file uploads failed when the `single_thread` configuration was enabled. @matyhtf
- Fixed an issue where compilation could not find the specific file path if the same variable was already defined in `config.m4`. @matyhtf
- Fixed an issue in `Swoole\Process\Pool` where processes could not exit properly upon timeout. @matyhtf
- Fixed an issue in `SWOOLE_THREAD` mode where calling `putenv` caused the program to crash. @matyhtf
- Fixed an issue in `SWOOLE_THREAD` mode where event callback functions could not be set for independent ports. @matyhtf
- Fixed an issue in `SWOOLE_THREAD` mode where runtime parameters could not be retrieved in events such as `onWorkerStart`. @matyhtf
- Fixed an issue where Postgresql would degrade to synchronous mode when receiving large amounts of data under coroutine. @NathanFreeman
- Optimized the parameter judgment logic of `swoole_substr_json_decode`/`swoole_substr_unserialize` functions. @Appla
- Fixed an issue with CPU affinity settings in `config.m4`. @remicollet
- In the Http service, if the process restarts, the underlying layer will send a 500 Internal Server to requests waiting in the queue, close the connection, and discard these requests after sending. @NathanFreeman
- Since the runtime configuration relied upon by the `stream factory` and `stream ops` in the PHP underlying is not thread-safe, in multi-thread mode, only the main thread is allowed to modify these runtime configurations before creating child threads. @matyhtf
- Fixed an issue in `SWOOLE_THREAD` mode where the heartbeat detection did not function properly. @matyhtf
6.0.0 - Added multi-threading support, require the ZTS version of PHP. Add `--enable-swoole-thread` option to the configure command to activate it.
- Added a new thread class `Swoole\Thread`. @matyhtf
- Introduced thread lock `Swoole\Thread\Lock`. @matyhtf
- Added thread atomic counter `Swoole\Thread\Atomic`, `Swoole\Thread\Atomic\Long`. @matyhtf
- Added safe concurrent containers `Swoole\Thread\Map`, `Swoole\Thread\ArrayList`, `Swoole\Thread\Queue`. @matyhtf
- The file asynchronous operation supports using `io_uring` as the underlying engine for file asynchronous operations. When liburing is installed and Swoole is compiled with the --enable-iouring option, the asynchronous operations of functions such as file_get_contents, file_put_contents, fopen, fclose, fread, fwrite, mkdir, unlink, fsync, fdatasync, rename, fstat, lstat, and filesize will be implemented by io_uring. @matyhtf @NathanFreeman
- Upgraded `Boost Context` to version 1.84. Now, Loongson CPUs can also support coroutines. @NathanFreeman
- Added `Swoole\Thread\Map::find()` method. @matyhtf
- Added `Swoole\Thread\ArrayList::find()` method. @matyhtf
- Added `Swoole\Thread\ArrayList::offsetUnset()` method. @matyhtf
- Added `Swoole\Process::getAffinity()` method. @matyhtf
- Added `Swoole\Thread::setName()` method. @matyhtf
- Added `Swoole\Thread::setAffinity()` method. @matyhtf
- Added `Swoole\Thread::getAffinity()` method. @matyhtf
- Added `Swoole\Thread::setPriority()` method. @matyhtf
- Added `Swoole\Thread::getPriority()` method. @matyhtf
- Added `Swoole\Thread::gettid()` method.
- The file asynchronous engine `iouring` supports multi-threaded polling mode `IORING_SETUP_SQPOLL`. @NathanFreeman
- Added `iouring_workers` to modify the number of `iouring` threads. @NathanFreeman
- Added `iouring_flags` to support modifying the `iouring` working mode. @NathanFreeman
- Added `Swoole\Thread\Barrier` for multi-thread synchronization barrier. @matyhtf
- Added new function and class to set cookies. @matyhtf @NathanFreeman
- Added `non-blocking, reentrant coroutine mutex lock`, which can be used between processes/threads without blocking them. @NathanFreeman
- `Swoole\Coroutine\Socket::getOption()` supports the `TCP_INFO` option. @matyhtf
- `Swoole\Client` synchronous blocking client supports `http` proxy. @matyhtf
- Added asynchronous non-blocking `TCP/UDP/Unix socket` client `Swoole\Async\Client`. @matyhtf
- Optimized the `Swoole\Redis\Server::format()` method to support zero-copy memory, support `redis` nested structure. @matyhtf
- Supports the high-performance compression tool `Zstd`. You only need to add `--enable-zstd` when compiling `Swoole`, and then `zstd` can be used to compress or decode responses between the `http` client and server. @NathanFreeman
- Fixed the issue where installation via `pecl` was not possible. @remicollet
- Fixed the bug where setting `keepalive` was not possible for `Swoole\Coroutine\FastCGI\Client`. @NathanFreeman
- Fixed the issue where exceeding the `max_input_vars` would throw an error, causing the process to restart repeatedly. @NathanFreeman
- Fixed unknown issues caused by using `Swoole\Event::wait()` within a coroutine. @matyhtf
- Fixed the problem where `proc_open` does not support pty in coroutine mode. @matyhtf
- Fixed segmentation fault issues with `pdo_sqlite` on PHP 8.3. @NathanFreeman
- Fixed unnecessary warnings during the compilation of `Swoole`. @Appla @NathanFreeward
- Fixed the error thrown by zend_fetch_resource2_ex when `STDOUT/STDERR` are already closed. @Appla @matyhtf
- Fixed ineffective `set_tcp_nodelay` configuration. @matyhtf
- Fixed the occasional unreachable branch issue during file upload. @NathanFreeman
- Fixed the problem where setting `dispatch_func` would cause PHP's internals to throw errors. @NathanFreeman
- Fixed the deprecation of AC_PROG_CC_C99 in autoconf >= 2.70. @petk
- Capture exceptions when thread creation fails. @matyhtf
- Fixed the undefined problem with `_tsrm_ls_cache`. @jingjingxyk
- Fixed the fatal compile error with `GCC 14`. @remicollet
- Fixed the dynamic property issue in `Swoole\Http2\Request`. @guandeng
- Fixed the occasional resource unavailability issue in the `pgsql` coroutine client. @NathanFreeman
- Fixed the issue of 503 errors due to not resetting related parameters during process restart. @matyhtf
- Fixed the inconsistency between `$request->server['request_method']` and `$request->getMethod()` when `HTTP2` is enabled. @matyhtf
- Fixed incorrect `content-type` when uploading files. @matyhtf
- Fixed code errors in the `http2` coroutine client. @matyhtf
- Fixed the missing `worker_id` property in `Swoole\Server`. @cjavad
- Fixed errors related to `brotli` in `config.m4`. @fundawang
- Fixed the invalid `Swoole\Http\Response::create` under multi-threading. @matyhtf
- Fixed compilation errors in the `macos` environment. @matyhtf
- Fixed the issue of threads not being able to exit safely. @matyhtf
- Fixed the issue where the static variable for response time returned by `Swoole\Http\Response` in multi-threaded mode was not generated separately for each thread. @matyhtf @NathanFreeman
- Fixed `Fatal error` issue caused by `PHP-8.4`'s `timeout` feature in ZTS mode. @matyhtf
- Fixed compatibility issue with the `exit()` `hook` function for `PHP-8.4`. @remicollet
- Fixed the issue where `Swoole\Thread::getNativeId()` did not work in `cygwin`. @matyhtf
- Fixed the issue causing `SIGSEGV` in `Swoole\Coroutine::getaddrinfo()` method. @matyhtf
- Fixed the issue where the runtime TCP module did not support dynamically enabling SSL encryption. @matyhtf
- Fixed the issue where the HTTP client had an incorrect timeout after running for a long time. @matyhtf
- Fixed the problem where the mutex lock of `Swoole\Table` could not be used before the process exited. @matyhtf
- Fixed the failure of `Swoole\Server::stop()` when using named parameters. @matyhtf
- Fixed the crash caused by `Swoole\Thread\Map::toArray()` not copying the key. @matyhtf
- Fixed the issue of being unable to delete nested numeric keys in `Swoole\Thread\Map`. @matyhtf
- Removed unnecessary checks for `socket structs`. @petk
- Upgraded Swoole Library. @deminy
- Added support for status code 451 in `Swoole\Http\Response`. @abnegate
- Synchronized `file` operation code across different PHP versions. @NathanFreeman
- Synchronized `pdo` operation code across different PHP versions. @NathanFreeman
- Optimized the code for `Socket::ssl_recv()`. @matyhtf
- Improved config.m4; some configurations can now set library locations via `pkg-config`. @NathanFreeman
- Optimized the use of dynamic arrays during `request header parsing`. @NathanFreeman
- Optimized file descriptor `fd` lifecycle issues in multi-threading mode. @matyhtf
- Optimized some fundamental coroutine logic. @matyhtf
- Upgraded the Oracle database version for CI testing. @gvenzl
- Optimized the underlying logic of `sendfile`. @matyhtf
- Replaced `PHP_DEF_HAVE` with `AC_DEFINE_UNQUOTED` in `config.m4`. @petk
- Optimized the logic related to `heartbeat`, `shutdown`, and `stop` for the server in multi-threaded mode. @matyhtf
- Optimized to avoid linking `librt` when `glibc` version is greater than 2.17. @matyhtf
- Enhanced the HTTP client to accept duplicate request headers. @matyhtf
- Optimized `Swoole\Http\Response::write()`. @matyhtf
- `Swoole\Http\Response::write()` can now send HTTP/2 protocol. @matyhtf
- Compatible with `PHP 8.4`. @matyhtf @NathanFreeman
- Added the ability for asynchronous writing at the underlying socket level. @matyhtf
- Optimized `Swoole\Http\Response`. @NathanFreeman
- Improved underlying error messages. @matyhtf
- Supported sharing PHP native sockets in multi-threaded mode. @matyhtf
- Optimized static file service and fixed static file path error issues. @matyhtf
- Multi-thread mode `SWOOLE_THREAD` supports restarting worker threads. @matyhtf
- Multi-thread mode `SWOOLE_THREAD` supports starting timers in the `Manager` thread. @matyhtf
- Compatible with the `curl` extension of `PHP-8.4`. @matyhtf @NathanFreeman
- Rewrite the underlying `Swoole` code using `iouring`. @matyhtf @NathanFreeman
- Optimized timers so that synchronous processes do not depend on signals. @matyhtf
- Optimized the `Swoole\Coroutine\System::waitSignal()` method to allow listening to multiple signals simultaneously. @matyhtf
- No longer supports `PHP 8.0`.
- No longer supports `Swoole\Coroutine\MySQL` coroutine client.
- No longer supports `Swoole\Coroutine\Redis` coroutine client.
- No longer supports `Swoole\Coroutine\PostgreSQL` coroutine client.
- Removed `Swoole\Coroutine\System::fread()`, `Swoole\Coroutine\System::fwrite()`, and `Swoole\Coroutine\System::fgets()` methods.
6.0.0RC1 - Added `non-blocking, reentrant coroutine mutex lock`, which can be used between processes/threads without blocking them. @NathanFreeman
- `Swoole\Coroutine\Socket::getoption()` supports the `TCPINFO` feature. @matyhtf
- `Swoole\Client` synchronous blocking client supports `http` proxy. @matyhtf
- Added asynchronous non-blocking `TCP/UDP/Unix socket` client `Swoole\Async\client`. @matyhtf
- Optimized the `Swoole\Redis\server::format()` method to support zero-copy memory, compatible with the `Redis` protocol. @matyhtf
- Fixed `Fatal error` issue caused by `PHP-8.4`'s `timeout` feature in ZTS mode. @matyhtf
- Fixed compatibility issue with the `exit()` function in `swoole` for `PHP-8.4`. @remicollet
- Fixed the issue where `Swoole\Thread::getNativeId()` did not work in `cygwin`. @matyhtf
- Fixed the issue causing `SIGSEGV` in `Swoole\Coroutine::getaddrinfo()` method. @matyhtf
- Fixed the issue where the runtime TCP module did not support dynamically enabling SSL encryption. @matyhtf
- Fixed the issue where the HTTP client had an incorrect timeout after running for a long time. @matyhtf
- Fixed the problem where the mutex lock of `Swoole\Table` could not be used before the process exited. @matyhtf
- Fixed the failure of `Swoole\Server::stop()` when using named parameters. @matyhtf
- Fixed the issue with the `toArray` function of concurrent containers in `SWOOLE_THREAD` multi-thread mode. @matyhtf
- Fixed the issue of being unable to delete nested numeric keys in `Swoole\Thread\Map` in `SWOOLE_THREAD` multi-thread mode. @matyhtf
- Multi-thread mode `SWOOLE_THREAD` supports restarting worker threads. @matyhtf
- Multi-thread mode `SWOOLE_THREAD` supports starting timers in the `Manager` thread. @matyhtf
- Compatible with the `curl` extension of `PHP-8.4`. @matyhtf @NathanFreeman
- Refactored `iouring`. @matyhtf @NathanFreeman
- Optimized timers so that synchronous processes do not depend on signals. @matyhtf
- Optimized the `Swoole\Coroutine\System::waitSignal()` method to allow listening to multiple signals simultaneously. @matyhtf
- This version is a `pre-release` and should not be used in production environments, only in testing environments.
Show complete changelog