Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 19, 2026·2 min de lecture

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.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Swoole Overview
Commande CLI universelle
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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires