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

ReactPHP — Event-Driven Non-Blocking I/O for PHP

ReactPHP is a low-level library for event-driven programming in PHP that provides an event loop, stream abstractions, and async I/O primitives for building non-blocking network applications.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
ReactPHP Overview
Commande d'installation directe
npx -y tokrepo@latest install 19716db7-53c1-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

ReactPHP brings the event-driven programming model to PHP. Inspired by Node.js and Reactor pattern implementations, it provides a composable set of libraries for building async HTTP servers, clients, and stream processors in pure PHP.

What ReactPHP Does

  • Provides an event loop for non-blocking I/O operations
  • Includes an HTTP server and client for async web applications
  • Offers stream abstractions for reading and writing data without blocking
  • Supports async DNS resolution, filesystem access, and child processes
  • Enables promise-based workflows for managing asynchronous results

Architecture Overview

ReactPHP is organized as a collection of small Composer packages centered around the event loop component. The loop uses the best available backend (ext-ev, ext-event, ext-uv, or a stream_select fallback). All I/O components — sockets, streams, HTTP, DNS — register callbacks with the loop and process data as it becomes available, enabling a single PHP process to handle many concurrent connections.

Self-Hosting & Configuration

  • Install individual components via Composer (e.g., react/http, react/socket)
  • Start the event loop with ReactEventLoopLoop::run()
  • Configure server listening address and port in your PHP script
  • Tune OS limits (file descriptors, TCP backlog) for high concurrency
  • Run as a persistent process using systemd or supervisord

Key Features

  • Modular component design — use only what you need
  • Promise-based async API following Promises/A+ semantics
  • Built-in HTTP server capable of handling concurrent requests
  • Stream processing with back-pressure support
  • No C extensions required for basic functionality

Comparison with Similar Tools

  • Swoole — coroutine-based C extension; ReactPHP is pure PHP with callback/promise patterns
  • Workerman — multi-process PHP server; ReactPHP is a library toolkit rather than a server framework
  • Amphp — similar async PHP library using fibers; ReactPHP uses promises and callbacks
  • Node.js — JavaScript event-driven runtime; ReactPHP applies the same model to PHP
  • Guzzle — synchronous HTTP client; ReactPHP's HTTP client is fully non-blocking

FAQ

Q: Can ReactPHP work with existing synchronous PHP code? A: Blocking calls will block the entire event loop. Use ReactPHP's async alternatives or run blocking code in child processes.

Q: Is ReactPHP production-ready? A: Yes. Its core components are stable and used in production for WebSocket servers, API gateways, and real-time applications.

Q: How does ReactPHP compare to PHP Fibers? A: PHP Fibers (8.1+) enable coroutine-style code. ReactPHP can use fibers internally while maintaining its promise-based public API.

Q: Does ReactPHP support WebSocket? A: Yes. The react/socket and community packages like Ratchet provide WebSocket server capabilities.

Sources

Fil de discussion

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

Actifs similaires