Get Started with Swoole

Swoole is released as a PHP extension (PECL) and run as a PHP CLI.

Try it with Docker

Please check the Try Swoole with Docker

Installation

Please check the prerequisites and installation guide.

Hello world

The following code is a Swoole HTTP Server returning 'Hello World':

<?php
use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;

$server = new Swoole\HTTP\Server("127.0.0.1", 9501);

$server->on("start", function (Server $server) {
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});

$server->on("request", function (Request $request, Response $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$server->start();

To run the server, put the code into a file named server.php. Then execute it with PHP CLI:

$ php server.php
$ curl http://127.0.0.1:9501/

Interested with Swoole? Get Started with Swoole now!