Open Swoole 4.11.0 released with HTTP2 improvements, PHP GRPC server, bug fixes and more

Published:

Open Swoole 4.11.0 is a major release with multiple HTTP2 new features, bug fixes and improvements for building reliable GRPC services. GRPC for PHP is also provided since this version.

Official Open Swoole version 4.11.0Official Open Swoole version 4.11.0

The major improvement in this version is around HTTP2 protocols and GRPC. Many bugs are fixed for HTTP2 and now you can use the Open Swoole HTTP2 server with browsers and common HTTP2 clients or GRPC clients.

New feature: allow HTTP2 client and server to set custom HTTP2 settings

The following HTTP2 settings are supported since OpenSwoole v4.11 which are required for GRPC:

  • http2_header_table_size
  • http2_initial_window_size
  • http2_max_concurrent_streams
  • http2_max_frame_size
  • http2_max_header_list_size

HTTP2 server settings:

<?php

$http = new swoole_http_server('127.0.0.1', 0, SWOOLE_BASE);
$http->set([
    'worker_num' => 1,
    'log_file' => '/dev/null',
    'open_http2_protocol' => true,
    'http2_header_table_size' => 4095,
    'http2_initial_window_size' => 65534,
    'http2_max_concurrent_streams' => 1281,
    'http2_max_frame_size' => 16383,
    'http2_max_header_list_size' => 4095,
]);

HTTP2 client settings:

<?php
Co\run(function () {
    $domain = 'cloudflare.com';
    $c = new Client($domain, 443, true);
    $c->set([
        'http2_header_table_size' => 4095,
        'http2_initial_window_size' => 65534,
        'http2_max_concurrent_streams' => 1281,
        'http2_max_frame_size' => 16383,
        'http2_max_header_list_size' => 4095,
    ]);
    var_dump($c->stats('local_settings'));
});

OpenSwoole GRPC for PHP

PHP GRPC Server is provided by OpenSwoole including the following features:

  • Native GRPC implementation compliant
  • PHP/PHP-FPM GRPC client compliant
  • Open Swoole GRPC Compiler provided
  • GRPC unary mode support
  • GRPC server side stream mode
  • GRPC server side interceptors

You can find the GRPC compiler at https://openswoole.com/docs/modules/grpc-compiler.

You can find the preview of Open Swoole GRPC server and client library and examples repo at https://github.com/openswoole/grpc.

New feature: support http_index_files at HTTP2 server

You can use Open Swoole HTTP and HTTP2 servers to serve static files when enabling enable_static_handler configuration.

You can also set the index file of your server with server setting http_index_files:

<?php
$serv->set([
    'http_index_files' => ['index.html', 'index.txt'],
]);

This index file settings is supported by both HTTP and HTTP2 server.

Bug fixed: $server->getWorkerPid()

Now the API returns a correct worker pid when being called from another worker context. You can find more about this API at /docs/modules/swoole-server-getWorkerPid.

Bug fixed: init window size in http2 server

A bug at HTTP2 server is fixed to support large response size.

Postgres Client improvements

There are a few improvements at the Postgres client within Open Swoole based on community feedback.

Now Postgres client returns empty array if the result set is empty instead returning false indicating there are issues with the query.

You can get the result status with API $connection->resultStatus. There are multiple constant enums for $connection->resultStatus added to compare with the status get from the API:

  • \OPENSWOOLE_PGRES_EMPTY_QUERY
  • \OPENSWOOLE_PGRES_COMMAND_OK
  • \OPENSWOOLE_PGRES_TUPLES_OK
  • \OPENSWOOLE_PGRES_BAD_RESPONSE
  • \OPENSWOOLE_PGRES_NONFATAL_ERROR
  • \OPENSWOOLE_PGRES_FATAL_ERROR

You can find more about Postgres client at /docs/modules/swoole-coroutine-postgres.

New API added: $pg->reset() and $pg->status()

You can reset the connection status and get the connection status with these two new API. You can find more about these new APIs at /docs/modules/swoole-coroutine-postgres.

Deprecated: redis server

Redis server in Open Swoole is a feature to provide TCP server with Redis like protocols. It is marked as deprecated and will be removed in the future versions.

Other

Since OpenSwoole v4.11.0, PHP7.2/7.3 support are removed as they are not supported by the PHP team.

There are many bug fixes and improvement by the community contributors.

List of changes in v4.11.0

. HTTP2 server: allow HTTP2 client and server to set custom HTTP2 settings
. Support static compile with PHP CLI
. New feature: support http_index_files at HTTP2 server
. CI: Remove PHP7.2/7.3 support as they are not supported by the PHP team
. Bug fixed: Fix HTTP2 client and respect max_concurrent_streams settings
. HTTP2: Update HTTP2 default max concurrent streams per connection to be 1280
. Bug fixed: Respect server side settings at HTTP2 client
. Optimize signal-driven timer code (@hauptmedia)
. Bug fixed: $server->getWorkerPid does not return the correct worker pid when being called from another worker context
. Bug fixed: init window size in http2 server
. Deprecated: redis server
. Bug fixed: close HTTP2 connection when there are errors
. Close connection when a process is stopped and it is managing http2 sessions
. Bug fixed: fix user land timer is not stopping when the server is shutting down
. Postgres client: return empty array if the result set is empty
. Postgres client: provide constant enums for $connection->resultStatus
. Postgres client: added new API $pg->reset() and $pg->status() (@RedChops)
. CI and tests: fixed many bugs in tests and improved the CI and testing (@hauptmedia)
. Build fix for gcc < 4.9 (@dmz-uk)

Thanks the Open Swoole Contributors

  • @hauptmedia fixed many bugs in testing and improved the CI system of Open Swoole.
  • @RedChops reported several bugs in Postgres client and added new Postgres client API
  • @dmz-uk fixed Open Swoole build issues for gcc < 4.9
  • @Ocramius PR fixes for IDE helper
  • @Ahmard PR fixes for IDE helper
  • @nazmulpcc PR fixes for IDE helper

You can upgrade to Open Swoole v4.11.0 now:

pecl install openswoole

Or use Docker images:

docker pull openswoole/swoole:latest

If you need to install Open Swoole or look at other update methods, checkout the installation documentation and how to update Open Swoole.