Get Started with Swoole

Notice: ext-swoole is supported until v4.7.1, use ext-openswoole >= v4.7.1. Latest version: pecl install openswoole-4.9.1

Open Swoole is released as a PHP PECL (PHP Extension Community Library) extension (written in C++) and runs as a PHP CLI application, simply by running $ php server.php. You can read more about the PECL Repository and even browse extensions like Swoole. Using the PECL Repository is an official way to install additional extensions to the PHP language, you can think of it like an add-on/plug-in which gets compiled, installed and loaded with PHP.

There a are a few ways to install Swoole on different systems, at first it can seem complicated if you have never installed a PHP extension before but once you read the basics its actually really easy and simple.

Try it with Docker

Please check the Try Swoole with Docker guide.


Please check the prerequisites first and then the installation guide.

Open Swoole can be installed via PECL, Open Swoole PPA Repository (Ubuntu or Debian) or manually by compiling source code from GitHub.

Latest Updates

As with any open source project, Swoole always aims to provide the most reliable stability and the most powerful features in the latest released version. Please ensure as much as possible that you are using the latest version of Swoole and PHP.

Hello World

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


use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;

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

$server->on("Start", function(Server $server)
    echo "Swoole http server is started at\n";

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


To run the server, put the code into a file named server.php.

Then execute on the command line:


# Start the HTTP server
$ php server.php

# On another terminal...
$ curl

Interested with Swoole? Get Started with Swoole now!


Because Swoole uses multiple processes and uses a stateful program model, some PHP applications rely heavily on super globals which could lead to a process crash when using Swoole, so currently the following software is incompatible with Swoole:

  • Xdebug
  • phptrace
  • aop
  • molten
  • xhprof
  • Phalcon
  • BlackFire

You should read Swoole Tools for more information on alternatives.