Swoole supports the coroutine feature in 2016, but the underlying stackless scheme is based on setJMP/LongjMP implementation. Therefore, coroutines cannot be used in certain scenarios, such as call_user_func, array_map, __destruct. The logic in large applications is complex, and it’s easy to get caught up in a team of people working together. Using the coroutine API in forbidden scenarios can cause all sorts of puzzling problems. It limits the range of coroutines.

New version 4.0 implements a new coroutine kernel based on boost. Context 1.60 assembly code. In addition to storing PHP function call stacks, C stack context storage is added. Implements support for all PHP syntax. Coroutines can now be used in any PHP function, including call_user_func, reflection, magic methods, and array_map.

Coroutines can now be used anywhere in PHP code, and developers no longer need to worry about usage scenarios. Version 4.0 we with SwooleDistributed/Swoft/EasySwoole framework, the author has carried on the close cooperation, gray scale trial in a large number of projects. Stability and robustness have reached industrial standards. It can be used in the production environment of large projects.

go(function() {     array_map("test", 
                                                                            array("func start\n"));     echo "co end\n";
                                                                                });   function test($p) {
                                                                                    echo $p;     co::sleep(1);     
                                                                                echo "func end \n"; }Copy the code

4.0The branch usesC++11Standard, recommended useGCC - 4.8 -Or later.

Global variable isolation

In the new version, global variables are isolated at the bottom level, and multiple Swoole\Server instances can now be created using Swoole\Process.

for ($i = 0; $i < 2; $i++)
{
    $p = new swoole_process(function () use ($i) {
        $port = 9501 + $i;
        $http = new swoole_http_server("127.0.0.1", $port);
        $http->on("start", function ($server) use ($port) {
            echo "Swoole http server is started at http://127.0.0.1:{$port}\n";
        });
        $http->on("request", function ($request, $response) {
            $response->header("Content-Type", "text/plain");
            $response->end("Hello World\n");
        });
        $http->start();
    }, false, false);
    $p->start();
}Copy the code

Other updates

  • Fixed an issue where the HTTP2 server could not send more than 16K data to Chrome clients

  • Fixed the problem that the Task process cannot restart in BASE mode

  • Added Channel->peek method for peeping data

  • Fixed Server->pause/resume being unavailable under SWOOLE_PROCESS

  • Remove Linux AIO and now use thread pools for asynchronous file IO regardless of setup

  • Support for MySQL stored procedures

Download 4.0

  • GITHUB:github.com/swoole/swoo…

  • Open Source China: gitee.com/swoole/swoo…

  • PECL:pecl.php.net/package/swo…