swoole-expert

Review Swoole PHP code for coroutine safety and runtime hook configuration.

2|Updated Jan 22, 2026
One-click install
npx skills add https://github.com/abnegate/claudes --skill swoole-expert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swoole-expert
Source: https://github.com/abnegate/claudes/tree/main/skills/swoole-expert
Command: npx skills add https://github.com/abnegate/claudes --skill swoole-expert

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building Swoole applications often fails in subtle ways—leaking state across requests, blocking inside coroutines, misusing runtime hooks, or mishandling graceful reloads—leading to hard-to-debug production incidents.

Core Features & Use Cases

  • Long-running process correctness: Clarifies object lifetimes and what must not rely on php-fpm behaviors (superglobals, session_start, echo/exit/header, static state).
  • Coroutine safety patterns: Covers coroutine container rules, cooperative scheduling behavior, cancellation/time limits, and safe cleanup with defer.
  • Production-grade Swoole reference: Provides detailed guidance for servers (HTTP/WebSocket/TCP), events and settings, concurrency primitives (Channel/WaitGroup/Barrier), runtime hook flags (including SWOOLE_HOOK_ALL), pooling rules, and the most common pitfalls with tuning and debugging.

Quick Start

Use the swoole-expert skill to review your Swoole server code for coroutine safety, correct hook configuration, and graceful reload behavior.

Frequently Asked Questions about swoole-expert

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent state leaks in Swoole long-running workers?

Swoole long-running workers leak state when you rely on php-fpm behaviors like superglobals, session_start, or static variables. You must manage object lifetimes explicitly and avoid shared state across resident worker processes.

What does SWOOLE_HOOK_ALL do for PHP coroutines?

SWOOLE_HOOK_ALL enables runtime hooks that rewrite blocking PHP I/O operations into coroutine-safe asynchronous operations. Enabling it is a non-negotiable default to prevent blocking inside coroutines and ensure cooperative scheduling.

How do I implement connection pooling for Swoole PHP coroutines?

Swoole connection pooling requires per-coroutine connection ownership to prevent race conditions. You must enforce lifecycle rules that fetch and release connections within the coroutine boundary, avoiding shared state pitfalls specific to resident workers.

Why does my Swoole server block inside a coroutine?

Swoole coroutines block when runtime hook flags are misconfigured or when executing CPU-bound tasks. You must use SWOOLE_HOOK_ALL to hook blocking I/O and apply concurrency primitives like Channels for safe cooperative scheduling.

Does php-fpm session_start work with Swoole HTTP servers?

php-fpm session_start does not work correctly with Swoole HTTP servers because resident worker processes share state across requests. You must manage session data explicitly within the coroutine container to avoid cross-request contamination.

How to configure graceful reload in production Swoole servers?

Production Swoole graceful reload requires safe cleanup using defer to release resources within the coroutine container before the worker terminates. You must apply lifecycle rules to avoid dropping active TCP or WebSocket connections during reloads.