Coroutine based Async PHP programming framework

Build high-performance, scalable, concurrent TCP, UDP, Unix Socket, HTTP, WebSocket services with PHP and fluent Coroutine API.

Write your next async application server with Swoole Coroutine API and PHP.

Get started in 10 minutes Tutorial Documentation Community

Compared with other async programming frameworks or softwares such as Nginx, Tornado, Node.js, Swoole has the built-in async, multiple threads I/O modules. Developers can use sync or async, coroutine API to write the applications. Swoole PHP network framework enhances the efficiency of R&D team, enable them to focus on the development of innovative products.

Event-driven, Coroutine, asynchronous programming for PHP

Async TCP / UDP / HTTP / Websocket / HTTP2 client/server side API

IPv4 / IPv6 / Unixsocket / TCP/ UDP and SSL / TLS support

Fast serializer / unserializer

High performance, scalable, support C1000K

Milliseconds task scheduler

Open Source


Get started

  • 1


    Linux users

    pecl install swoole
    Mac users

    brew install php 
    pecl install swoole
  • 2

    HTTP Server

    $server = new Swoole\HTTP\Server("", 9501);
    $server->on("start", function (Swoole\Http\Server $server) {
        echo "Swoole http server is started at\n";
    $server->on("request", function (Swoole\Http\Request $request, Swoole\Http\Response $response) {
        $response->header("Content-Type", "text/plain");
        $response->end("Hello World\n");
  • 3

    WebSocket Server

    $server = new Swoole\Websocket\Server("", 9502);
    $server->on('open', function($server, $req) {
        echo "connection open: {$req->fd}\n";
    $server->on('message', function($server, $frame) {
        echo "received message: {$frame->data}\n";
        $server->push($frame->fd, json_encode(["hello", "world"]));
    $server->on('close', function($server, $fd) {
        echo "connection close: {$fd}\n";
  • 4

    TCP Server

    $server = new Swoole\Server("", 9503);
    $server->on('connect', function ($server, $fd){
        echo "connection open: {$fd}\n";
    $server->on('receive', function ($server, $fd, $from_id, $data) {
        $server->send($fd, "Swoole: {$data}");
    $server->on('close', function ($server, $fd) {
        echo "connection close: {$fd}\n";
  • 5

    Coroutine TCP Client

    $client = new Swoole\Client(SWOOLE_SOCK_TCP);
    if (!$client->connect('', 9501, 0.5)) {
        exit("connect failed. Error: {$client->errCode}\n");
    $client->send("hello world\n");
    echo $client->recv();
  • 6

    Coroutine Redis / HTTP / WebSocket Client

    $redis = new Swoole\Coroutine\Redis();
    $redis->connect('', 6379);
    $val = $redis->get('key');
    echo $val;
    $http = new Swoole\Coroutine\Http\Client('', 80);
    echo $http->body;
  • 7

    Coroutine Tasks

    $server = new Swoole\Http\Server("", 9501, SWOOLE_BASE);
        'worker_num' => 1,
        'task_worker_num' => 2,
    $server->on('Request', function ($request, $response) use ($server) {
        $tasks[0] = ['time' => 0];
        $tasks[1] = ['data' => '', 'code' => 200];
        $result = $server->taskCo($tasks, 1.5);
        $response->end('<pre>Task Result: '.var_export($result, true));
    $server->on('Task', function (Swoole\Server $server, $task_id, $worker_id, $data) {
        if ($server->worker_id == 1) {
        $data['done'] = time();
        $data['worker_id'] = $server->worker_id;
        return $data;

Use cases

Mobile API server

Internet of Things

Micro services

Web API or web application

Gaming server

Live chat system