OpenSwoole 26.11.1 released with bug fixes and reliability improvements

OpenSwoole 26.11.1 adds the HTTP QUERY method, supports CURLOPT_PROTOCOLS_STR in the coroutine curl hook, updates the bundled HTTP parser to llhttp 9.4.4, and fixes bugs in the HTTP, HTTP/2 and WebSocket servers. We recommend that all users of OpenSwoole 26.x upgrade.

You can upgrade to OpenSwoole v26.11.1 now:

pecl install openswoole-26.11.1

Or install it with PIE:

pie install openswoole/ext-openswoole

Or use Docker images:

docker pull openswoole/openswoole:26.11-php8.6-alpine

Find more OpenSwoole docker images at OpenSwoole Docker images at Docker Hub

New Features

HTTP QUERY Method

The HTTP server supports the QUERY method from RFC 10008, a safe and idempotent method that carries the query in the request body. Form bodies sent with QUERY are parsed into $request->post the same way as for POST, PUT, PATCH and DELETE (#414):

use OpenSwoole\Http\Server;

$server = new Server('0.0.0.0', 9501);
$server->on('Request', function (OpenSwoole\Http\Request $request, OpenSwoole\Http\Response $response) {
    if ($request->getMethod() === 'QUERY') {
        $response->end(json_encode($request->post));
        return;
    }
    $response->end('OK');
});
$server->start();

The coroutine HTTP client can send it with $client->setMethod('QUERY').

CURLOPT_PROTOCOLS_STR in the Coroutine curl Hook

curl_setopt() accepts CURLOPT_PROTOCOLS_STR and CURLOPT_REDIR_PROTOCOLS_STR with SWOOLE_HOOK_NATIVE_CURL (libcurl 7.85 or later), the string options that replace the deprecated CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS (#412):

use OpenSwoole\Runtime;

Runtime::enableCoroutine(Runtime::HOOK_ALL);

co::run(function () {
    $ch = curl_init('https://openswoole.com/');
    curl_setopt($ch, CURLOPT_PROTOCOLS_STR, 'https');
    curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS_STR, 'https');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_exec($ch);
});

When open_basedir is set, a value that contains file or all is refused with a warning, as in native PHP.

Updated Bundled Libraries

  • llhttp, the HTTP parser of the HTTP server and the coroutine HTTP client, is upgraded from 2.0.5 to 9.4.4 (#413)
  • the nghttp2 HPACK code used by the HTTP/2 server and client is upgraded to 1.71.0, and its symbols are no longer exported from openswoole.so, so it cannot collide with the libnghttp2 that other extensions load
  • the bundled hiredis is upgraded to 1.5.1

PHP 8.6.0

PHP 8.6.0 is now released, and the PHP 8.6 Docker images are built on PHP 8.6.0 instead of the release candidate. The PHP 8.6 Alpine images are built without linux/arm/v6 until the official PHP 8.6 Alpine image is available for that platform.

Changes

The HTTP parser is stricter: requests with a space between a header name and the colon, folded header lines, or raw bytes above 0x7F in the request target get 400 Bad Request. Encode such bytes in the URL with percent-encoding instead. The coroutine HTTP client applies the same rules to responses.

The WebSocket server follows RFC 6455 more closely: frames from a client must be masked, and unknown opcodes or a new message sent before a fragmented one is finished close the connection. Ping, pong and close frames accept payloads up to the 125 bytes the RFC allows. A coroutine HTTP client with websocket_mask set to false can no longer send to an OpenSwoole WebSocket server.

The HTTP/2 server rejects frames on a stream the client has closed, removes the padding of DATA frames, checks WINDOW_UPDATE increments, and with send_yield waits for the stream window before sending. The HTTP/2 server and client reject header blocks with invalid Huffman padding, as RFC 7541 requires.

SOCKS5 proxy target hosts, usernames and passwords longer than 255 bytes are refused, and a refused CONNECT reply fails the connection.

Bug Fixes

  • Fix WebSocket frames losing their opcode and FIN flag with several reactor threads in SWOOLE_PROCESS mode
  • Fix WebSocket connections when the upgrade request is followed by more data in the same packet
  • Fix a fragmented WebSocket message with an empty first frame losing its opcode
  • Fix the payload of WebSocket ping and pong frames sent with the 16 bit length form
  • Fix the WebSocket fragment buffer not being released when a connection closes during a fragmented message
  • Fix multipart form data of an unfinished part being kept for the next request, and its temporary file and memory not being released
  • Fix Request::create()->parse() with a multipart body
  • Fix Response::create() with a Coroutine\Socket
  • Fix chunked requests with Content-Length: 0 that do not end with a zero length chunk
  • Fix client certificates larger than the read buffer with ssl_client_cert_file
  • Fix DTLS connections above max_connection
  • Fix HTTP/2 response header blocks larger than the header buffer
  • Fix HTTP/2 send_yield responses not ending when a send fails or the client resets the stream or closes the connection
  • Fix HTTP/2 GOAWAY frames carrying the error code in the flags
  • Fix discarded HTTP/2 DATA frames not counting against the connection window
  • Fix buffer_high_watermark and buffer_low_watermark being reset when the server starts
  • Fix the $row argument of the PostgreSQL statement fetch methods being ignored
  • Fix a Lock becoming unusable in other processes after a child process exits, or after destroy() is called in another process
  • Fix a Table losing rows with concurrent writers after a child process exits
  • Fix Lock::lockwait() requiring an argument
  • Fix the open_redis_protocol parser with null bulk strings, integer elements, empty arrays and bulk lengths below -1
  • Fix the length protocol with unsigned 32 bit lengths of 2^31 and more
  • Fix the SOCKS5 handshake with short replies and IPv4 targets
  • Fix Coroutine\Client::peek() with a length of 0 or less
  • Fix curl_setopt_array() not stopping at a refused option in the coroutine curl hook

Thanks to Martin Fris for the llhttp upgrade, the QUERY method and the curl protocol options.

Upgrade

If you need to install OpenSwoole or look at other update methods, checkout the installation documentation and how to update Open Swoole. The changes that can affect existing applications are listed in the upgrade guide.

Install the core library, which fixes socket_last_error() and socket_clear_error() with the sockets hook:

composer require openswoole/core:26.11.1