Scaling PHP
Lucas Arruda
lucas@ciandt.com
@lunascarruda
Handrus Nogueira
handrus@taller.net.br
@handrus
Lucas Arruda
Software Architect @ CI&T
Open-Source enthusiast
~10 yrs on the road
Based on Campinas-SP
Zend Certified Engi...
Handrus
Software Architect / Dev @ Taller
Open-Source and Agile
~10 yrs on the road
Based on Bauru-SP/Florianópolis-SC
Dru...
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 ca...
Fine tune your php.ini!
● memory_limit
memory_get_usage() / memory_get_peak_usage()
● realpath_cache_size
realpath_cache_g...
mod_php
vs.
FastCGI
vs.
PHP-FPM
ob_flush()
flush()
?
PHP ACCELERATORS
Alternative PHP Cache (APC)
Zend OPcache
XCache
apc.shm_size
apc.ttl
apc.num_files_hint
apc.gc_ttl
apc.max_file_size
apc.stat
APC OPcache
opcache.revalidate_freq
opcache....
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!
Persistent load balancing
Sh...
Options
Shared file-system
Database
Memcache / Redis
session.name
session.save_handler
session.save_path
Sharing
session d...
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?!
How dependent of your actual
environment are you?
timezonepaths connection string
limits
timeouts
Number of triesAPI Keys
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
Presentation Deck
http://goo.gl/0cV1KT
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
co...
Scaling php - Intercon php
Scaling php - Intercon php
Scaling php - Intercon php
Upcoming SlideShare
Loading in …5
×

Scaling php - Intercon php

1,145 views

Published on

Talk about scalability in the php world, given at the first Intercon PHP (2014) organized by Imasters and PHPSP community.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,145
On SlideShare
0
From Embeds
0
Number of Embeds
28
Actions
Shares
0
Downloads
7
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Scaling php - Intercon php

  1. 1. Scaling PHP Lucas Arruda lucas@ciandt.com @lunascarruda Handrus Nogueira handrus@taller.net.br @handrus
  2. 2. Lucas Arruda Software Architect @ CI&T Open-Source enthusiast ~10 yrs on the road Based on Campinas-SP Zend Certified Engineer PHP 5.3 Drupaler for 4 yrs Google Cloud Platform Qualified Dev.
  3. 3. Handrus Software Architect / Dev @ Taller Open-Source and Agile ~10 yrs on the road Based on Bauru-SP/Florianópolis-SC Drupaler for 3 yrs
  4. 4. The Basics
  5. 5. Use the latest PHP stable version
  6. 6. Use the latest PHP stable version
  7. 7. 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!
  8. 8. 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!
  9. 9. mod_php vs. FastCGI vs. PHP-FPM
  10. 10. ob_flush() flush() ?
  11. 11. PHP ACCELERATORS
  12. 12. Alternative PHP Cache (APC) Zend OPcache XCache
  13. 13. apc.shm_size apc.ttl apc.num_files_hint apc.gc_ttl apc.max_file_size apc.stat APC OPcache opcache.revalidate_freq opcache.validate_timestamps opcache.max_accelerated_files opcache.memory_consumption opcache.interned_strings_buffer opcache.fast_shutdown XCache xcache.size xcache.count xcache.slots xcache.ttl xcache.gc_interval xcache.cacher xcache.stat xcache.var_size xcache.var_count xcache.var_slots xcache.var_ttl xcache.var_maxttl xcache.var_gc_interval
  14. 14. Zephir
  15. 15. Scaling PHP Horizontally
  16. 16. Does your app use session data? No: you’re good to go! Yes: then you’ll need to manage this data across multiple servers.
  17. 17. Sharing session data Fault tolerant No bottleneck Cheaper buut… it needs architecure changes! Persistent load balancing Sharing session data PHP Session Management Persistent load balacing Single point of failure Bottleneck Expensive
  18. 18. Options Shared file-system Database Memcache / Redis session.name session.save_handler session.save_path Sharing session data Handlers files user memcache
  19. 19. Avoid database specific queries. Good libraries can help (Doctrine FTW!) If not possible Document like any Technical Debt!
  20. 20. And choose well your database!! ● MySQL ● MariaDB ● PerconaDB Version?!
  21. 21. How dependent of your actual environment are you? timezonepaths connection string limits timeouts Number of triesAPI Keys
  22. 22. Caching Mechanisms
  23. 23. APC for caching user data Memcache for key/value storage (URI/HTML?) tmpfs/ramfs for all file-based caching
  24. 24. Reverse proxying Nginx Varnish
  25. 25. ...
  26. 26. Q&A ciandt.com Presentation Deck http://goo.gl/0cV1KT
  27. 27. THANKS FOR BEING HERE! Please evaluate this presentation! http://goo.gl/P8ZDfc (3 questions only)
  28. 28. @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

×