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.
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.
The following HTTP2 settings are supported since OpenSwoole v4.11 which are required for GRPC:
<?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,
]);
<?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'));
});
PHP GRPC Server is provided by OpenSwoole including the following features:
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.
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.
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.
A bug at HTTP2 server is fixed to support large response size.
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:
You can find more about Postgres client at /docs/modules/swoole-coroutine-postgres.
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.
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.
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.
. 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)
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.
Join 4,000+ others and never miss out on new tips, tutorials, and more.