Open Swoole 4.5.3 released

Published:

Swoole v4.5.3 is released with multiple new features and enhancement.

Swoole Process Manager

Swoole Process Manager can be used to manage multiple different functions and execute them within multiple processes.

Example:

<?php
$pm = new Swoole\Process\ProcessManager();
$atomic = new Atomic(0);
$pm->add(function (Pool $pool, int $workerId) use ($atomic) {
    usleep(100000);
    $atomic->wakeup();
});
$pm->add(function (Pool $pool, int $workerId) use ($atomic) {
    $atomic->wait(1.5);
    $pool->shutdown();
});
$pm->start();

Barrier

We can use Barrier to sync multiple coroutines since v4.5.3, wait until multiple coroutines are finished.

Example:

<?php
declare(strict_types=1);

use Swoole\Coroutine\Barrier;

Co\run(function() {
    $barrier = Barrier::make();
    $count = 0;
    $N = 4;
    foreach (range(1, $N) as $i) {
        \Swoole\Coroutine::create(function () use ($barrier, &$count) {
            System::sleep(5);
            $count++;
        });
    }
    Barrier::wait($barrier);
});

Coroutine::parallel

Coroutine::parallel can be used to run multiple copy of the function in multiple coroutines concurrently.

Example:

<?php
declare(strict_types=1);

use Swoole\Coroutine;
use Swoole\Runtime;
use function Swoole\Coroutine\parallel;

Co\run(function() {
    $c = 4;
    $results = [];
    parallel($c, function () use (&$results) {
        System::sleep(2);
        $results[] = System::gethostbyname('localhost');
    });
    var_dump($results);
});

List of changes in v4.5.3

New APIs
---
+ Added `Swoole\Process\ProcessManager` (swoole/library#88f147b) (@huanghantao)
+ Added ArrayObject::append, StringObject::equals (swoole/library#f28556f) (@matyhtf)
+ Added Coroutine::parallel (swoole/library#6aa89a9) (@matyhtf)
+ Added Coroutine\Barrier (swoole/library#2988b2a) (@matyhtf)

Enhancement
---
+ Added usePipelineRead to support streaming call-in http2 client (#3354) (@twose)
+ Do not create the file before receive body when a download (#3381) (@twose)
+ Added `bind_address` and `bind_port` setting for coroutine http client (#3390) (@huanghantao)
+ Added `lowercase_header` option for HttpClient (#3399) (@matyhtf)
+ Added `tcp_user_timeout` option for `Swoole\Server` (#3404) (@huanghantao)
+ Added `Coroutine\Socket` event barrier (#3409) (@matyhtf)
+ Added specify swString memory allocator (#3418) (@matyhtf)
+ Support cURL `__toString` (swoole/library#38) (@twose)
+ Added `lowercase_header` to fix cURL header name (swoole/library#e7c2a82) (@twose)
+ Set wait count directly in WaitGroup constructor (swoole/library#2fb228b8) (@matyhtf)
+ Added `CURLOPT_REDIR_PROTOCOLS` (swoole/library#46) (@sy-records)
+ Support trailer for HTTP 1.1 (#3485) (@huanghantao)
+ Support yield when sleeping less 1ms (#3487) (@Yurunsoft)
+ Support get soft link file in the static handler (#3569) (@LeiZhang-Hunter)
+ Close WebSocket connection immediately after the server call close method (#3570) (@matyhtf)
+ Support hook stream_set_blocking (#3585) (@Yurunsoft)
+ Support HTTP2 flow control in async HTTP2 Server (#3486) (@huanghantao) (@matyhtf)
+ Support free socket buffer after onPackage is called (#3551) (@huanghantao) (@matyhtf)

Fixed
---
* Fixed WebSocket coredump, handle protocol status error (#3359) (@twose)
* Fixed swSignalfd_setup and fix possible nullptr error in wait_signal (#3360) (@twose)
* Fixed `Swoole\Server::close` throw a error when set dispatch_func (#3365) (@twose)
* Fixed format_buffer init problem when use `Swoole\Redis\Server::format` (#3369) (@matyhtf) (@twose)
* Fixed get mac address in MacOS (#3372) (@twose)
* Fixed MySQL test case (#3374) (@qiqizjl)
* Fixed PHP8 compatibility (#3384) (#3458) (#3578) (#3598) (@twose)
* Fixed missing php_error_docref, timeout_event and return value in hook socket write and read (#3383) (@twose)
* Fixed the server could not be stopped during the `WorkerStart` phase (#3382) (@huanghantao)
* Fixed coredump because of heart thread operate conn->socket (#3396) (@huanghantao)
* Fixed send yield logic bug (#3397) (@twose) (@matyhtf)
* Fixed compile problem in Cygwin64 (#3400) (@twose)
* Fixed WebSocket finish property invalid (#3410) (@matyhtf)
* Fixed build error when losing sys/random.h (#3427) (@huanghantao)
* Fixed missing MySQL transaction error, update the test (#3429) (@twose)
* Fixed the result of `stream_select` (#3440) (@Yurunsoft)
* Fixed lose `SIGCHLD` when use `Coroutine\System` to create the child process (#3446) (@huanghantao)
* Fixed sendwait not support SSL mode (#3459) (@huanghantao)
* Fixed `ArrayObject` and `StringObject` bug (swoole/library#44) (@matyhtf)
* Fixed mysqli error, typo (swoole/library#45) (@sy-records)
* Fixed can not get correct Swoole\Client::errCode if `open_eof_check` is set (#3478) (@huanghantao)
* Fixed fix atomic->wait()/wakeup() in MacOS (#3476) (@Yurunsoft)
* Fixed Client::connect return 0 when serve refused (#3484) (@matyhtf)
* Fixed nullptr_t is not declared in alpine (#3488) (@limingxinleo)
* Fixed fix HTTP Client download filename bug, double-free memory (#3489) (@Yurunsoft)
* Fixed fix memory leak of Server\Port (#3507) (@twose)
* Fixed fix mqtt parse protocal error (318e33a) (84d8214) (80327b3) (efe6c63) (@GXhua) (@sy-records)
* Fixed Coroutine\Http\Client->getHeaderOut coredump (#3534) (@matyhtf)
* Fixed missing error info of SSL verify (#3535) (@twose)
* Fixed update Swoole benchmark link in README (#3536) (@sy-records) (@santalex)
* Fixed fix HTTP header/cookie injection when using CRLF (#3539) (#3541) (#3545) (chromium1337) (@huanghantao)
* Fixed fix the typo variable in #3463 (#3547) (chromium1337) (@huanghantao)
* Fixed the typo introduced in pull request #3463 (#3547) (@deminy)
* Fixed set coroutine WebSocket server frame->fd (#3549) (@huanghantao)
* Fixed connection leak when heart thread check the connection status (#3534) (@matyhtf)
* Fixed don't need block signals in the process pool (#3582) (@huanghantao) (@matyhtf)
* Fixed don't send headers by SAPI (#3571) (@twose) (@sshymko)
* Fixed set error code and error message when curl execution fails (swoole/library#1b6c65e) (@sy-records)
* Fixed swoole_socket_coro accept bug when call setProtocol function will cause coredump (#3591) (@matyhtf)

Kernel
---
* Use the CPP style (#3349) (#3351) (#3454) (#3479) (#3490) (@huanghantao) (@matyhtf)
* Added Swoole known strings to improve PHP object property reading (#3363) (@huanghantao)
* Improve code (#3350) (#3356) (#3357) (#3423) (#3426) (#3461) (#3463) (#3472) (#3557) (#3583) (@huanghantao) (@twose) (@matyhtf)
* Optimize tests (#3416) (#3481) (#3558) (@matyhtf)
* Simplify table int type (#3407) (@matyhtf)
* Added sw_memset_zero and replace bzero (#3419) (@CismonX)
* Optimize log module (#3432) (@matyhtf)
* Refactor libswoole (#3448) (#3473) (#3475) (#3492) (#3494) (#3497) (#3498) (#3526) (@matyhtf)
* Refactor header deps (#3457) (@matyhtf) (@huanghantao)
* Added `Channel::count()` and `Channel::get_bytes()` (f001581) (@matyhtf)
* Added scope guard (#3504) (@huanghantao)
* Added libswoole coverage test (#3431) (@huanghantao)
* Added lib-swoole/ext-swoole MacOS test (#3521) (@huanghantao)
* Added lib-swoole/ext-swoole Alpine test (#3537) (@limingxinleo)

You can upgrade to Swoole v4.5.3 now:

pecl install openswoole