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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay