Configs2026年5月19日·1 分钟阅读

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.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
ReactPHP Overview
通用 CLI 安装命令
npx tokrepo install 19716db7-53c1-11f1-9bc6-00163e2b0d79

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产