Scaling PHP 
Lucas Arruda 
lucas@ciandt.com 
@lunascarruda 
Handrus Nogueira 
handrus@taller.net.br 
@handrus
Lucas Arruda 
Based on Campinas-SP 
Software Architect @ CI&T 
Open-Source enthusiast 
~10 yrs on the road 
Zend Certified Engineer PHP 5.3 
Google Cloud Platform Qualified Dev. 
Drupaler for 4 yrs
Handrus 
Based on Bauru-SP/Florianópolis-SC 
Software Architect / Dev @ Taller 
Open-Source and Agile 
~10 yrs on the road 
Drupaler for 3 yrs
The Basics
Use the latest PHP stable version
Use the latest PHP stable version
Disable unnecessary PHP extensions and web-server modules 
● PHP extensions consume memory heap 
● Some badly written can cause memory leaks 
● The same applies for web-server modules 
● Disable if you don’t need them!
Fine tune your php.ini! 
● memory_limit 
memory_get_usage() / memory_get_peak_usage() 
● realpath_cache_size 
realpath_cache_get() 
● realpath_cache_ttl 
Max execution per thread - will affect memory usage!
mod_php 
vs. 
FastCGI 
vs. 
PHP-FPM
ob_flush() 
flush() 
?
PHP ACCELERATORS
Alternative PHP Cache (APC) 
Zend OPcache 
XCache
APC OPcache XCache
Zephir
Scaling PHP 
Horizontally
Does your app use 
session data? 
No: you’re good to go! 
Yes: then you’ll need to 
manage this data across 
multiple servers.
Sharing session data 
Fault tolerant 
No bottleneck 
Cheaper 
buut… it needs architecure changes! 
PHP Session 
Management 
Persistent load balancing 
Sharing session data 
Persistent load balacing 
Single point of failure 
Bottleneck 
Expensive
Options 
Shared file-system 
Database 
Memcache / Redis 
Sharing 
session data 
session.name 
session.save_handler 
session.save_path 
Handlers 
files 
user 
memcache
Avoid database specific 
queries. 
Good libraries can help 
(Doctrine FTW!) 
If not possible 
Document like any 
Technical Debt!
And choose well 
your database!! 
● MySQL 
● MariaDB 
● PerconaDB 
Version?!
paths timezone connection string 
limits 
timeouts 
API Keys Number of tries 
How dependent of your actual 
environment are you?
Caching Mechanisms
APC 
for caching user data 
Memcache 
for key/value storage (URI/HTML?) 
tmpfs/ramfs 
for all file-based caching
Reverse proxying 
Nginx Varnish
...
Q&A 
ciandt.com
THANKS 
FOR 
BEING 
HERE! 
Please evaluate this presentation! 
http://goo.gl/P8ZDfc 
(3 questions only)
@lunascarruda 
lunascar@gmail.com 
google.com/+LucasArruda 
fb.com/lucasnarruda 
linkedin.com/in/larruda 
github.com/larruda 
coderbits.com/larruda 
@handrus 
handrus@gmail.com 
google.com/+HandrusNogueira 
fb.com/handrus 
linkedin.com/in/handrus 
github.com/handrus 
coderbits.com/handrus

InterConPHP 2014 - Scaling PHP