Threads in PHP
„will changes the world“
Stefan Willkommer
Co-Founder and CTO
w
agner_tim
78
@
Tim Wagner
Co-Founder and Lead Architect
@
sw
illkom
m
er
Tiger
Sissi
me ;)
Annette
Uschi
me ah
Tim
Barbecue
Let’s
DIFFERENTIATE
EVENTLOOPS
FORKS
THREADS
What is a
THREAD
Process-Model
without
THREADS
Process-Model
with
THREADS
What do we
NEED
PHP 5.3+
compiled thread-safe
--enable-maintainer-zts
PECL extension
pthreads
my first
THREAD
my first
THREAD
What is a
STACKABLE
enabling sharing and synchronizing
Data over THREADS
tasks which can be processed
by a WORKER
What can be
SHARED
everything which is
SERIALIZABLE
sharing Data 
with a
Stackable
sharing Data 
with a
Stackable
sharing Data 
with a
Stackable
What is a
WORKER
allows stacking of
DATA
like a
QUEUE
using a
Worker
using a
Worker
SYNCHRONISATION
and
CONCURRENCY
HANDLING
waiting for Threads with
join()
enables waiting for one or more
THREADS
makes sure that result is available in
THREAD
waiting by using
Join
waiting by using
Join
waiting by using
Join
synchronizing Threads with
synchronized()
synchronize with
synchronized()
synchronize with
synchronized()
synchronize with
synchronized()
concurrency handling by using
MUTEX
synchronize with
Mutex
synchronize with
Mutex
synchronize with
Mutex
sharing
Resources
sharing
Sockets
sharing
Sockets
sharing
Sockets
What to do with all these
POSSIBILITIES
GOOD
everything
is
BAD
Runtime
ApplicationServer
PersistenceContainer Web
MQ Objects WebServer
Worker Threads
Socket	

0.0.0.0:8587
Socket	

0.0.0.0:8585
Socket	

0.0.0.0:8586
HTTPRemoteMethodMessage
Timer
MBeans	

SBeans	

!
Worker
Performance comparison
Test Profile
Setup: 1 Webserver + 1 DB Server
Virtualisation: KVM / Intel Xeon / 4 Cores
OS: Debian wheezy
Magento: 1.13.1.0 EE
Amount of Products: 10,000
milliseconds
0
65
130
195
260
Homepage Category Page Detailpage
AS, mod PHP nginx, PHP FPM
The power of
MEMORY
Performance comparison
Test Profile
Setup: 1 Webserver + 1 DB Server
Virtualisation: KVM / Intel Xeon / 4 Cores
OS: Debian wheezy
Magento: 1.13.1.0 EE
Amount of Products: 10,000
milliseconds
0
65
130
195
260
Homepage Category Page Detailpage
AS, Mage Servlet nginx, PHP FPM
60%
in average about
faster
280%
in average about
faster
What’s
NEXT?
https://github.com/techdivision/phptek_2014
https://github.com/krakjoe/pthreads
https://computing.llnl.gov/tutorials/pthreads/
http://appserver.io
https://github.com/techdivision/TechDivision_ApplicationServer
Ressources
Thank you!
Questions?

Threads in PHP - Presentation