swoole

 

 


openswoole

apt install -y software-properties-common
add-apt-repository ppa:ondrej/php -y

add-apt-repository ppa:openswoole/ppa -y
apt install -y php8.0-openswoole

 


Tips

 

[1] Set port in config.php

port 的 settings 不影響 $server->set()

$config = require_once __DIR__ . "/config.php";
$port = $config["server"]["port"];
$server = new OpenSwoole\Http\Server("0.0.0.0", $port, Server::SIMPLE_MODE, Constant::SOCK_TCP | Constant::SSL);
$server->set($config["settings"]);

[2] To pass a variable to the on("Start") callback function in OpenSwoole

# "use" keyword to import the variable from the outer scope.

$server->on("Start", function (Server $server) use ($port) {
    echo "OpenSwoole http server is started at https://0.0.0.0:$port\n";
});

 

Creative Commons license icon Creative Commons license icon