31
Scaling PHP Lucas Arruda [email protected] @lunascarruda Handrus Nogueira [email protected] @handrus

InterConPHP 2014 - Scaling PHP

Embed Size (px)

DESCRIPTION

Tips and hits on how to scale your PHP application, from tuning your php.ini settings and using accelerators till going through caching mechanisms, reverse proxying and infrastructure setups.

Citation preview

Page 1: InterConPHP 2014 - Scaling PHP

Scaling PHP

Lucas [email protected]

@lunascarruda

Handrus [email protected]

@handrus

Page 2: InterConPHP 2014 - Scaling PHP

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.

Page 3: InterConPHP 2014 - Scaling PHP

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

Page 4: InterConPHP 2014 - Scaling PHP

The Basics

Page 5: InterConPHP 2014 - Scaling PHP

Use the latest PHP stable version

Page 6: InterConPHP 2014 - Scaling PHP

Use the latest PHP stable version

Page 7: InterConPHP 2014 - Scaling PHP

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!

Page 8: InterConPHP 2014 - Scaling PHP

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!

Page 9: InterConPHP 2014 - Scaling PHP

mod_phpvs.

FastCGIvs.

PHP-FPM

Page 10: InterConPHP 2014 - Scaling PHP

ob_flush()flush()

?

Page 11: InterConPHP 2014 - Scaling PHP

PHP ACCELERATORS

Page 12: InterConPHP 2014 - Scaling PHP

Alternative PHP Cache (APC)

Zend OPcache

XCache

Page 13: InterConPHP 2014 - Scaling PHP

APC OPcache XCache

Page 14: InterConPHP 2014 - Scaling PHP
Page 15: InterConPHP 2014 - Scaling PHP

Zephir

Page 16: InterConPHP 2014 - Scaling PHP

Scaling PHPHorizontally

Page 17: InterConPHP 2014 - Scaling PHP

Does your app use session data?

No: you’re good to go!

Yes: then you’ll need to manage this data across multiple servers.

Page 18: InterConPHP 2014 - Scaling PHP

Sharing session data

Fault tolerantNo bottleneckCheaper

buut… it needs architecure changes!

Persistent load balancing

Sharing session data

PHP Session Management

Persistent load balacing

Single point of failureBottleneckExpensive

Page 19: InterConPHP 2014 - Scaling PHP

Options

Shared file-systemDatabaseMemcache / Redis

session.name

session.save_handler

session.save_path

Sharing session data

Handlers

filesusermemcache

Page 20: InterConPHP 2014 - Scaling PHP

Avoid database specific queries.

Good libraries can help (Doctrine FTW!)

If not possible Document like any Technical Debt!

Page 21: InterConPHP 2014 - Scaling PHP

And choose wellyour database!!

● MySQL● MariaDB● PerconaDB

Version?!

Page 22: InterConPHP 2014 - Scaling PHP
Page 23: InterConPHP 2014 - Scaling PHP

How dependent of your actual environment are you?

timezonepaths connection stringlimits

timeouts

Number of triesAPI Keys

Page 24: InterConPHP 2014 - Scaling PHP

Caching Mechanisms

Page 25: InterConPHP 2014 - Scaling PHP

APCfor caching user data

Memcachefor key/value storage (URI/HTML?)

tmpfs/ramfsfor all file-based caching

Page 26: InterConPHP 2014 - Scaling PHP

Reverse proxying

Nginx Varnish

Page 27: InterConPHP 2014 - Scaling PHP
Page 29: InterConPHP 2014 - Scaling PHP

Q&Aciandt.com

Page 30: InterConPHP 2014 - Scaling PHP

THANKS FOR

BEINGHERE!

Please evaluate this presentation!http://goo.gl/P8ZDfc

(3 questions only)

Page 31: InterConPHP 2014 - Scaling PHP

@lunascarruda

[email protected]

google.com/+LucasArruda

fb.com/lucasnarruda

linkedin.com/in/larruda

github.com/larruda

coderbits.com/larruda

@handrus

[email protected]

google.com/+HandrusNogueira

fb.com/handrus

linkedin.com/in/handrus

github.com/handrus

coderbits.com/handrus