ScriptsMay 19, 2026·2 min read

Swoole — Coroutine-Based Async PHP Runtime

Swoole is a high-performance coroutine-based asynchronous programming framework for PHP that turns PHP into a language capable of handling concurrent connections like Go or Node.js.

Agent ready

This asset can be read and installed directly by agents

TokRepo exposes a universal CLI command, install contract, metadata JSON, adapter-aware plan, and raw content links so agents can judge fit, risk, and next actions.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
Swoole Overview
Universal CLI install command
npx tokrepo install 9dd607d7-53c0-11f1-9bc6-00163e2b0d79

Introduction

Swoole extends PHP with an event-driven, coroutine-based concurrency model. It allows PHP developers to build high-performance TCP/UDP/HTTP/WebSocket servers without switching languages.

What Swoole Does

  • Adds native coroutine support to PHP for concurrent I/O
  • Provides built-in HTTP, WebSocket, and TCP/UDP servers
  • Implements async MySQL, PostgreSQL, and Redis clients
  • Offers process management and task worker pools
  • Supports millisecond-precision timers and signal handling

Architecture Overview

Swoole is a C extension for PHP that runs as a persistent process (not per-request like PHP-FPM). It uses an event loop powered by epoll/kqueue at its core, with a multi-process reactor model. Coroutines are stackful and scheduled cooperatively, yielding automatically on I/O operations so other coroutines can proceed.

Self-Hosting & Configuration

  • Install via PECL (pecl install swoole) or compile from source
  • Enable the extension in php.ini with extension=swoole.so
  • Configure worker count via $server->set(['worker_num' => 4])
  • Use Docker image phpswoole/swoole for containerized deployments
  • Set swoole.use_shortname to control function alias behavior

Key Features

  • Stackful coroutines with automatic yield on I/O
  • Built-in connection pooling for databases and Redis
  • HTTP/2 and WebSocket server support out of the box
  • Shared memory tables for inter-process data sharing
  • Process and task worker management with message passing

Comparison with Similar Tools

  • ReactPHP — event-loop async without coroutines; Swoole uses coroutines for synchronous-style code
  • Workerman — pure PHP async server; Swoole is a C extension with higher raw throughput
  • RoadRunner — Go-based PHP app server; Swoole runs entirely within PHP process space
  • FrankenPHP — embedded PHP in Caddy; Swoole provides its own server and async primitives
  • Node.js — similar event-driven model but Swoole lets teams keep their PHP codebase

FAQ

Q: Does Swoole work with Laravel? A: Yes. Laravel Octane provides a first-party Swoole adapter for persistent application serving.

Q: Can I use existing PHP libraries with Swoole? A: Most libraries work, but blocking I/O calls should be replaced with Swoole coroutine-aware clients for best performance.

Q: Is Swoole production-ready? A: Yes. It has been used in production by companies handling millions of concurrent connections since its initial release in 2012.

Q: What PHP versions does Swoole support? A: Swoole supports PHP 8.1 and above for the latest releases.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets