Asynchronous Programming with PHP: Swoole & PHP 8.4
This presentation, delivered at PHPKonf 2025 in Istanbul, provides an in-depth exploration of asynchronous programming in PHP—an area where the language has historically lagged behind more modern alternatives like Node.js or Go. With the rise of Swoole and improvements in PHP 8.x, asynchronous capabilities in PHP are now more accessible, powerful, and practical than ever.
🔍 What’s Inside?
✅ Synchronous vs. Asynchronous Programming
We begin by contrasting the traditional synchronous (blocking) model—where tasks execute sequentially—with asynchronous (non-blocking) architectures that enable concurrent execution and better resource utilization. This lays the groundwork for understanding why async is important.
✅ Where Async Shines
- The talk walks through use cases where asynchronous programming in PHP can bring the most value:
- High-concurrency web servers
- Real-time chat and notification systems
- Long-running tasks (e.g., file uploads, external API calls)
- Microservices, IoT, and event-driven architectures
✅ Tooling and Ecosystem
A comparison of popular async libraries and engines in PHP:
- Swoole (native extension, high performance, coroutine support)
- ReactPHP and AMPHP (pure PHP libraries)
The trade-offs between these tools in terms of performance, ease of use, server support, and deployment complexity are explored in detail.
✅ Swoole Internals Explained
- A large portion of the presentation focuses on Swoole, including:
- Event loop and coroutine fundamentals
- Architecture: Master, Reactor, Manager, Worker, and Task Worker processes
- Runtime hooks that make blocking PHP functions (like sleep(), file_get_contents(), or PDO) behave non-blockingly
- Shared memory via OpenSwoole\Table and atomic counters via OpenSwoole\Atomic
- Integration with frameworks like Laravel (Octane) and Symfony (Swoole Bundle)
✅ PHP 8.4 & Fibers
The session covers Fibers, introduced in PHP 8.1 and improved in later versions, which serve as the underlying mechanism for lightweight, controllable async flows. While not full async on their own, Fibers play a key role in userland coroutine implementations.
✅ Benchmarks & Real Projects
Includes real-world benchmarks and two demo projects built using OpenSwoole and PHP 8.4:
- A simple HTTP server
- A multiplayer Tic Tac Toe (XOX) game server
👨💻 Who Should Watch This?
This talk is ideal for:
- Backend developers building high-concurrency or real-time applications in PHP
- Teams looking to adopt async design patterns without switching to a different tech stack
- Engineers interested in PHP internals and performance tuning
- Anyone curious about using PHP beyond traditional web-request-response models
⚠️ Also Discussed: What Swoole Is Not
- It’s not a framework like Laravel or Symfony
- It’s not a drop-in web server replacement (though it can be used as one)
- It’s not ideal for low-traffic, CRUD-style apps
- It’s not a “magic bullet” — understanding DevOps and async architecture is essential
Speaker: Fatih M. Koç
Slides: This deck
Code Samples: https://github.com/fmkoc/phpkonf-2025