Quick Crash Course into Swoole for WLP3 Plugin Developers
May 17, 2025
Written as extension of https://www.reddit.com/r/WhitelabelPress/comments/1koubo8/new_abilities_for_the_daring_plugin_developer/
π “Swoole is really a new type of BEAST!”
Swoole fundamentally changes the PHP execution model from per-request stateless to long-running processes, bringing async I/O, coroutines, and performance on par with Node.js or Go. It’s a whole different paradigm from traditional PHP.
π¦ “Every require
/require_once
choice matters.”
In Swoole:
- Files are not reloaded per request like traditional PHP (which starts fresh on each HTTP request).
- Once included in a worker process, a file required once remains in memory until the process is restarted.
- Mistakes (like requiring a dev-only script globally) persist across requests and can cause memory leaks or unexpected behavior.
This forces you to be deliberate about where and when you load code.
β»οΈ “Resetting static/global objects for each request is a must.”
Because Swoole reuses worker processes:
- Global/static variables persist across requests, unlike traditional PHP.
- If you’re not careful, you can leak state between requests (user sessions, input data, temporary config, etc.).
- This is one of the biggest gotchas and the #1 reason people get bitten by unexpected bugs in Swoole.
Swoole encourages (and requires) a more disciplined, stateless mindset β like writing microservices in Node.js or Go.
πͺ “Cookies/redirects/die/exit statements work differently.”
die/exit
: Still terminates the current function, but because of the async/coroutine model, if misused, it may interfere with expected cleanup or coroutine execution.
setcookie()
and headers: Must be sent explicitly using the Swoole response object ($response->header()
, $response->cookie()
). Native PHP setcookie()
won’t work outside of certain runtime modes.
- Redirects: You handle them manually using
$response->status(302)
and $response->header('Location', '...')
.
- So yes, many classic PHP mechanisms don’t behave the same way or are not available at all β you need to use Swoole’s APIs instead.
π± “It weirdly forces you to become a better developer.”
Youβre forced to:
- Think about memory and state.
- Write cleaner, more modular, stateless code.
- Use dependency injection and reset object state.
- Embrace async programming, which broadens your skillset.
Itβs a crash course in systems-level, long-running app design β in PHP!
π “It’s insanely fast + more scalable compared to classic PHP with NGINX/Apache2”
Compared to traditional setups:
- No PHP-FPM overhead per request
- No process spawning for every page hit
- Fully async (non-blocking) I/O with coroutines
- Ideal for real-time apps (WebSockets, TCP servers, etc.)
Swoole apps can handle thousands of concurrent connections with less CPU and memory overhead than traditional stacks.

Neil
Lead dev @ WLP (WhiteLabelPress)