@17Live 大樓三樓 銀河灰會議室
Zeev Suraski
Co-founder of Zend, Co-architect of PHP
"Swoole is a strategic development in the evolution of PHP, bringing high performance async-IO based apps to the mainstream of the platform. This book is everything you need to unlock that power of your new async-PHP apps!"
"Swoole is a tremendous technology and a game changer for PHP developers. I started to play with it in 2017 and I created the first runtime for Expressive framework. The results have been incredible, huge performance improvement without using a web server, amazing! If you want to design asynchronous applications in PHP the book of Bruce Dou is a must."
Enrico Zimuel
Member of PHP-FIG and co-author of Expressive and Zend Framework
26
77
33
28
40
37
64
Since 2012
Open source based on Apache-2.0 License
16.3k start on Dec. 2020
More than 100 contributors
Adopted by many enterprises in China
Swoole Plus for enterprise support
Not a new language, but an extension for PHP
Provides many new features for traditional PHP
New lifecycle in Swoole
Server patterns, coroutine, async I/O, Process Management, etc.
It's still under active development
Stable for production environment
High performance
How do we serve PHP today?
PHP-FPM
mod_php for Apache
Both patterns are all stateless
Pros
Easy scaling
Simple, less risk causing memory leaks
Cons
States can't be shared between requests
States must rely on external storages
Resources can't be reused efficiently
Connection cost is expensive (like database)
Not good for high performance
FPM (FastCGI Process Manager)
SAPI: Adapters like PHP-Cli, PHP-Fpm or embeded
ZendVM: Composed with Compiler and Executor, like JVM in Java
Extension: Including PHP Extension and Zend Extension
blocking I/O model
Execute PHP Code
Initialize PHP Code
Database Request
HTTP API Request
Response
Include PHP Files
Actor
Erlang
CSP (Communicating Sequential Processes)
Golang, Swoole
STM (Software Transactional Memory)
Clojure
Ruby 3
Don't communicate by sharing memory; share memory by communicating. (Rob Pike)
Multiple actors can run at the same
Each actor has its own identifier and internal states
Actors communicate with each other by sending asynchronous messages
Every actor has an mailbox (queue)
Actors are isolated
Decoupled by channel
Pub/Sub Pattern
Shared memory and lock are implemented in channel
Only one active consumer can access data
Processes are anonymous
Use shared memory
No need for lock
All changes of data are encapsulated in transactions
Every thread has a copy of its working data and can change its value
Like transactions in database
Threads from different guilds can run in parallel
Threads that belong to the same Guild can’t execute in parallel (GGL)
Immutable objects can be shared (read) across Guilds
Guilds can communicate with each other using channel (deep copy)