Open Swoole 4.5.5 released: HTTP2 GOAWAY, PHP 8 Support, Co\map and more

Published:

Swoole v4.5.5 is released today with multiple new features and enhancement.

Swoole\Process\Manager

Process\Manager is added as an alias of Swoole\Process\ProcessManager.

HTTP2 server side goaway

The termination logic of HTTP2 server side connections has been improved. Now you can send GOAWAY packet to the connected HTTP2 clients and gracefully disconnect the connection:

<?php
$http = new Swoole\HTTP\Server('127.0.0.1', 9090, SWOOLE_BASE);
$http->set([
    'worker_num' => 1,
    'log_file' => '/dev/null',
    'open_http2_protocol' => true
]);
$http->on('request', function (Swoole\HTTP\Request $request, Swoole\HTTP\Response $response) {
    $response->goaway(SWOOLE_HTTP2_ERROR_NO_ERROR, 'NO_ERROR');
    $response->end($request->rawcontent());
});
$http->start();

You can find more on the API page: Swoole\Http\Response->goaway.

Co\map function is added

You can apply a function on a list of data and execute them concurrently with co\map.

<?php
Swoole\Coroutine\map(array $list, callable $fn, float $timeout = -1): array
<?php
<?php declare(strict_types=1);

use Swoole\Coroutine;
use function Swoole\Coroutine\map;

function fatorial(int $n): int
{
    return array_product(range($n, 1));
}

Coroutine\run(function () {
    $results = map([2, 3, 4], 'fatorial');
    print_r($results); // 2 6 24
});

PHP 8 Support

Multiple changes are made to align with PHP 8.0 changes, Swoole will support PHP 8 in the first time.

New server option: stats_file

Set a file location for Swoole server to priint the stats info to the file once per second.

<?php
$server->set(['stats_file' => './stats.txt']);

List of changes in v4.5.5

New APIs
---
+ Added Process\Manager and alias Process\ProcessManager (swoole/library#eac1ac5) (@matyhtf)
+ Support HTTP2 server-side GOAWAY (#3710) (@doubaokun)
+ Added Co\map() function (swoole/library#57) (@leocavalcante)

Enhancement
---
+ Support http2 client unix socket (#3668) (@sy-records)
+ Set the worker status to SW_WORKER_EXIT when the worker process exits (#3724) (@matyhtf)
+ Add send_queued_bytes and recv_queued_bytes in Server::getClientInfo() (#3721) (#3731) (@matyhtf) (@Yurunsoft)
+ Support option of stats_file (#3725) (@matyhtf) (@Yurunsoft)

Fixed
---
* Fixed PHP8 build (zend_compile_string change) (#3670) (@twose)
* Fixed PHP8 build (ext/sockets compatibility) (#3684) (@twose)
* Fixed PHP8 build (php_url_encode_hash_ex change) (#3713) (@remicollet)
* Fixed invalid conversion from 'const char*' to 'char*' for build (#3686) (@remicollet)
* Fixed HTTP2 client over HTTP proxy is not working (#3677) (@matyhtf) (@twose)
* Fixed PDO context data confusion (swoole/library#54) (@sy-records)

Kernel
---
* Code optimization (#3671) (#3689) (#3700) (#3701) (#3708) (#3718) (#3722) (#3723) (@matyhtf)

You can upgrade to Swoole v4.5.5 now:

pecl install openswoole