Repolode
swoole

swoole/swoole-src

A PHP extension providing an event-driven networking engine and coroutine runtime for building long-running TCP, UDP, HTTP, and WebSocket services.

Stars
18,927
Forks
3,147
Open issues
34
Last commit
13 hours ago

What is it?

Swoole is a PHP extension whose C/C++ core supplies an event loop, a coroutine scheduler, servers, clients, and protocol implementations. It lets PHP applications keep running as persistent network services and handle many concurrent connections without starting a separate PHP process per request.

The extension includes server classes for TCP, UDP, Unix sockets, HTTP, and WebSocket, along with coroutine clients for upstream TCP and HTTP calls. Coroutines let a worker run other tasks while one waits for supported I/O. Multiple worker processes can use several CPU cores, and task workers handle jobs that should not block request handling.

Swoole workers are long-lived, so global state and open resources can persist across requests and must be managed carefully. Coroutines provide concurrency rather than automatic CPU parallelism. The bundled PHP library adds connection pools for PDO, MySQLi, and Redis, along with utilities such as WaitGroup and Barrier.

Key features

  • 01Event-driven TCP, UDP, and Unix socket servers with multiple listening ports
  • 02HTTP and WebSocket servers built on request and message callbacks
  • 03Coroutine scheduler with channels and coroutine-aware socket and system I/O
  • 04Coroutine TCP, UDP, and HTTP clients for upstream calls
  • 05Runtime hooks that make selected blocking PHP functions yield inside coroutines
  • 06Process, shared table, and atomic APIs for interprocess coordination

Use cases

  • Building HTTP APIs that stay resident in memory across many requests
  • Serving real-time WebSocket messaging from PHP
  • Implementing custom TCP or UDP protocol gateways in PHP
  • Making concurrent calls to several upstream services within one request

Quick start

  1. 1

    Install the extension from PECL

    pecl install swoole
  2. 2

    Save the HTTP server example as server.php

  3. 3

    Run the server with PHP

    php server.php

Things to know

  • It is a PHP extension, so PHP must be installed and the extension must be loaded in php.ini.
  • Coroutines do not provide CPU parallelism; CPU-heavy code still blocks its worker.
  • Long-lived workers mean global and static state can persist across requests, so per-request data needs care.
  • The master branch targets Swoole 6.3 and PHP 8.2–8.5, so choose a released version for production.

In collections

Topics

FAQ

What is swoole-src?
A PHP extension providing an event-driven networking engine and coroutine runtime for building long-running TCP, UDP, HTTP, and WebSocket services. Swoole is a PHP extension whose C/C++ core supplies an event loop, a coroutine scheduler, servers, clients, and protocol implementations. It lets PHP applications keep running as persistent network services and handle many concurrent connections without starting a separate PHP process per request.
Is swoole-src free to use? What license does it have?
swoole-src is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is swoole-src still maintained?
Actively maintained. The last commit to swoole-src was on Oct 24, 2026.
What can I use swoole-src for?
Building HTTP APIs that stay resident in memory across many requests Serving real-time WebSocket messaging from PHP Implementing custom TCP or UDP protocol gateways in PHP Making concurrent calls to several upstream services within one request
How do I install swoole-src?
Install the extension from PECL: pecl install swoole Save the HTTP server example as server.php Run the server with PHP: php server.php
Where can I get swoole-src?
The source code and installation instructions are on GitHub: https://github.com/swoole/swoole-src

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects