DEV Community

hardyweb
hardyweb

Posted on

Compile PHP Swoole and test Swoole http server

*INSTALL SWOOLE *

apt install php-dev libc-ares-dev libcurl4-openssl-dev
Enter fullscreen mode Exit fullscreen mode
sudo pecl install -D 'enable-sockets="yes" enable-openssl="yes" enable-http2="yes" enable-mysqlnd="yes" enable-swoole-json="yes" enable-swoole-curl="yes" enable-cares="yes"' swoole
Enter fullscreen mode Exit fullscreen mode
echo "extension=swoole.so" > /etc/php/8.1/cli/conf.d/20-swoole.ini
Enter fullscreen mode Exit fullscreen mode

CHECK SWOOLE EXTENSION LOADED

php -m | grep swoole 
Enter fullscreen mode Exit fullscreen mode
php --ri swoole 
Enter fullscreen mode Exit fullscreen mode

TEST SWOOLE

<?php

    $http = new Swoole\Http\Server('0.0.0.0', 9501);

    $http->on("request", function ($request, $response) {
        $response->header("Content-Type", "text/plain");
        $response->end("Hello, Swoole!");
    });

     $http->start();
    ?>
Enter fullscreen mode Exit fullscreen mode
curl localhost:9501
Enter fullscreen mode Exit fullscreen mode

Buy Me A Coffee

Top comments (0)