talira

Coroutine-based concurrency library for PHP

open sourceApache-2.0self-hostablefree

Swoole is a PHP extension, with a C/C++ core, for building persistent network services and concurrent I/O applications. It provides an event loop and coroutine scheduler, event-driven TCP, UDP and Unix socket servers, HTTP and WebSocket servers, coroutine TCP and HTTP clients, runtime hooks that make supported PHP functions coroutine-aware, processes, shared memory tables and atomics, and timers. Servers run several long-lived worker processes to use every CPU core, with coroutines for concurrent I/O inside each worker. It installs with pecl install swoole.

Problems it solves

  • run PHP as a long-lived async server instead of PHP-FPM
  • handle thousands of concurrent connections in PHP
  • build a WebSocket server in PHP
  • make concurrent HTTP calls from PHP with coroutines

Features

  • event loop and coroutine scheduler
  • TCP, UDP and Unix socket servers
  • HTTP and WebSocket servers
  • coroutine clients
  • runtime hooks for PHP functions
  • processes, shared tables and atomics
  • timers

Limitations

  • Workers are long-lived: global and static state and open resources survive between requests, so per-request data must stay out of process state1

Alternatives

The same job

These do what Swoole does.

  1. FrankenPHP The modern PHP app server, written in Go

Compare Swoole with the top 3