SlideShare una empresa de Scribd logo
1 de 61
Descargar para leer sin conexión
1 #Dynatrace
Proper	
  configura-on	
  for	
  high	
  performance	
  websites	
  
Harald	
  Zeitlhofer	
  
April	
  2015	
  
	
  
Boost	
  your	
  website	
  by	
  running	
  
PHP	
  on	
  Nginx	
  
@HZeitlhofer	
  
harald.zeitlhofer@dynatrace.com	
  
	
  
2 #Dynatrace
Fast	
  PHP	
  applica-ons	
  
3 #Dynatrace
Applica-on	
  Performance	
  
4 #Dynatrace
Tips and tricks for high performance websites
5 #Dynatrace
Web	
  Request	
  handling	
  
6 #Dynatrace
Web	
  Request	
  handling	
  
7 #Dynatrace
PHP	
  
run	
  modes	
  
Apache	
  Module	
  
–  tradi-onal	
  approach	
  
–  used	
  for	
  most	
  PHP	
  
environments	
  
CGI	
  
–  Command	
  Line	
  Interface	
  (CLI)	
  
FastCGI	
  (PHP-­‐FPM)	
  
–  PHP	
  applica-on	
  server	
  
–  Run	
  mul-ple	
  PHP	
  worker	
  
processes	
  to	
  serve	
  CGI	
  requests	
  
8 #Dynatrace
Nginx	
  
Lightweight	
  HTTP	
  server	
  
Fast	
  especially	
  at	
  high	
  load	
  
Event	
  based	
  request	
  handling	
  
Open	
  Source	
  project	
  (BSD)	
  	
  
by	
  Igor	
  Sysoev	
  
Nginx,	
  Inc.	
  founded	
  in	
  2011	
  
9 #Dynatrace
Leading	
  among	
  	
  
top	
  10.000	
  websites	
  
10 #Dynatrace
but I could call
the FPM from Apache !
11 #Dynatrace
it’s not only
the FPM
yes,	
  but	
  ...	
  
it’s Nginx' event
based processing
that creates the
performance
advantage
12 #Dynatrace
Apache can also be operated
in an event mode !
13 #Dynatrace
it’s not 100%
event based...
yes,	
  but	
  ...	
  
14 #Dynatrace
prefork	
  mode	
  
one	
  process	
  per	
  request	
  
	
  
worker	
  mode	
  
mul-ple	
  threads	
  per	
  process,	
  
one	
  per	
  request	
  
	
  
worker	
  event	
  mode	
  
event	
  based	
  request	
  handling	
  
15 #Dynatrace
• mod_php	
  
• mod_fcgid	
  
• mod_fastcgi	
  
	
  
Integra-on	
  
• ngx_h5p_fastcgi_modul	
  
16 #Dynatrace
PHP-­‐FPM	
  
FastCGI	
  Process	
  Manager	
  
	
  
	
  
Available	
  since	
  5.3.3,	
  stable	
  since	
  5.4.1	
  
	
  
	
  
	
  
17 #Dynatrace
• Installa-on	
  
	
  
• Pool	
  configura-on	
  
/etc/php5/fpm/pool.d/www.conf
PHP-­‐FPM	
  
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000 # for Unix socket: unix:/var/run/php5-fpm.sock;
root@hzvm01:/etc/nginx/sites-enabled# ps -ef | grep php
root 6435 1 0 14:39 ? 00:00:32 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
spelix 6439 6435 0 14:39 ? 00:00:00 php-fpm: pool batch
spelix 6440 6435 0 14:39 ? 00:00:00 php-fpm: pool batch
www-data 10576 6435 1 18:45 ? 00:00:48 php-fpm: pool www
www-data 10920 6435 1 18:47 ? 00:00:47 php-fpm: pool www
www-data 10927 6435 1 18:47 ? 00:00:46 php-fpm: pool www
sudo apt-get install php5-fpm
18 #Dynatrace
• Pool	
  configura-on	
  
/etc/php5/fpm/pool.d/www.conf
PHP-­‐FPM	
  
[pool_name]
...
pm = [dynamic/static]
pm.max_children = 10
;only used for dynamic:
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_children
	
  
	
   	
  =	
  total	
  available	
  memory	
  /	
  memory	
  used	
  by	
  1	
  PHP	
  process	
  
19 #Dynatrace
Nginx	
  and	
  PHP-­‐FPM	
  
Integra-on	
  
20 #Dynatrace
• /etc/nginx/nginx.conf	
  
	
  
	
  
# max_clients = worker_processes * worker_connections
worker_processes 8; # number of CPUs
worker_rlimit_nofile 40000;
events {
worker_connections 1024;
multi_accept on;
}
21 #Dynatrace
• Communica-on	
  via	
  sockets	
  
•  TCP	
  vs	
  Unix	
  
•  Unix	
  slightly	
  faster	
  when	
  used	
  on	
  localhost	
  
•  Use	
  TCP	
  for	
  high	
  load	
  
location ~* .php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;
22 #Dynatrace
Transac-on	
  flow	
  
23 #Dynatrace
•  Sta-c	
  content	
  to	
  be	
  served	
  by	
  Nginx	
  
•  Dynamic	
  requests	
  to	
  be	
  sent	
  to	
  PHP-­‐FPM	
  
Integra-on	
  
server {
listen 80;
root /var/www/test;
index index.php index.html index.htm;
server_name test.whateveryourdomain.is;
location ~ .(html|js|css|gif|jpg|jpe|jpeg|png|bmp|tif|pdf|ico)$ {
try_files $uri =404;
}
location / {
try_files $uri $uri/ =404;
}
location ~* .php$ {
fastcgi_index index.php;
fastcgi_pass php;
include fastcgi_params;
}
}
24 #Dynatrace
hbp://www.mysite.com/news/browse/2014	
  
è	
  to	
  be	
  handled	
  by	
  index.php	
  
URL	
  rewrite	
  
...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php
...
25 #Dynatrace
hbp://www.mysite.com/news/browse/2014	
  
è	
  to	
  be	
  handled	
  by	
  index.php	
  
URL	
  rewrite	
  
upstream php {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name www.mysite.com;
location / {
try_files $uri $uri/ @missing;
}
location @missing {
rewrite (.*) /index.php;
}
location ~ .php$ {
fastcgi_index index.php;
include fastcgi_params;
fastcgi_pass php;
}
}
26 #Dynatrace
using	
  Nginx/PHP-­‐FPM	
  there’s	
  a	
  beber	
  way:	
  
URL	
  rewrite	
  
upstream php {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name www.mysite.com;
location /images {
try_files $uri =404;
}
location /scripts {
try_files $uri =404;
}
location / {
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/index.php;
fastcgi_pass php;
}
}
<?php
$params = explode('/', $_SERVER["DOCUMENT_URI"]);
...
27 #Dynatrace
• Easy	
  way	
  to	
  deploy	
  your	
  applica-on	
  
• All	
  source	
  files	
  packed	
  into	
  one	
  *.phar	
  file	
  
PHAR	
  –	
  PHP	
  Archives	
  
location ~* .(php|phar)$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/myapp.phar;
}
28 #Dynatrace
PHAR	
  example	
  
root@hzvm01:/var/www/app/src# ls -lrtR
.:
total 8
drwxrwxr-x 2 root root 4096 Oct 10 16:27 lib
-rw-r--r-- 1 root root 27 Oct 10 16:27 index.php
./lib:
total 4
-rw-r--r-- 1 root root 87 Oct 10 16:27 App.php
root@hzvm01:/var/www/app/src# cat index.php
<?php
$app = new App();
?>
root@hzvm01:/var/www/app/src# cat lib/App.php
<?php
class App {
function __construct() {
echo "Starting Applicationn";
}
}
29 #Dynatrace
PHAR	
  example	
  
location /myapp {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/myapp.phar;
}
root@hzvm01:/var/www/app# phar pack -f myapp.phar src
lib/App.php
index.php
root@hzvm01:/var/www/app# l myapp.phar
-rw-r--r-- 1 root root 6923 Oct 10 19:51 myapp.phar
30 #Dynatrace
PHAR	
  execu-on	
  
31 #Dynatrace
Performance	
  
32 #Dynatrace
• Nginx	
  running	
  with	
  default	
  segngs	
  
• Apache	
  
•  AllowOverride	
  None	
  
•  Mul--­‐process	
  mode	
  to	
  allow	
  usage	
  of	
  mod_php	
  
Benchmarking	
  Nginx	
  vs	
  Apache	
  
33 #Dynatrace
Sta-c	
  HTML,	
  10k	
  requests	
  
0	
  
1	
  
2	
  
3	
  
4	
  
5	
  
6	
  
7	
  
8	
  
9	
  
100	
   500	
   1000	
   2000	
  
Apache/2.4.9	
  
nginx/1.1.19	
  
concurrency	
  
Total	
  response	
  -me	
  [sec]	
  
34 #Dynatrace
Nginx	
  and	
  Caching	
  
35 #Dynatrace
• Part	
  of	
  the	
  Nginx	
  FastCGI	
  module	
  
Nginx	
  FastCGI	
  cache	
  
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=APPKEY:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
location ~* .php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_cache APPKEY;
fastcgi_cache_valid 200 60m;
}
36 #Dynatrace
Tes-ng	
  FastCGI	
  cache	
  
37 #Dynatrace
Tes-ng	
  FastCGI	
  cache	
  
38 #Dynatrace
Tes-ng	
  FastCGI	
  cache	
  
<?php
echo time()."n";
?>
39 #Dynatrace
• ngx_hbp_memcached_module	
  
Full	
  page	
  cache	
  with	
  Nginx	
  and	
  Memcached	
  
server {
location / {
set $memcached_key "$uri";
memcached_pass localhost:11211;
error_page 404 502 504 = @fallback;
}
location @fallback {
proxy_pass http://backend;
}
}
40 #Dynatrace
• PHP	
  	
  
Full	
  page	
  cache	
  with	
  Nginx	
  and	
  Memcached	
  
<?php
...
function cachePage($content) {
$c = new Memcached();
$c->addServer('localhost',11211);
$c->set($_SERVER[”REQUEST_URI"], $content);
}
...
$content = $this->renderPage();
$this->cachePage($content);
...
?>
41 #Dynatrace
PHP,	
  5k	
  requests,	
  concurrency	
  100	
  
0	
  
1	
  
2	
  
3	
  
4	
  
5	
  
6	
  
7	
  
8	
  
Apache+PHP	
   Nginx+PHP	
   Nginx+Memcached	
  
<?php
echo “Hello World”;
?>
42 #Dynatrace
• set	
  HTTP	
  response	
  expires	
  header	
  
Client	
  Side	
  Caching	
  
location ~ .(html|js|css|gif|jpg|jpe|jpeg|png|bmp|tif|pdf|ico)$ {
expires 90d;
access_log off;
error_log off;
try_files $uri =404;
}
43 #Dynatrace
• keep	
  handlers	
  for	
  requested	
  sta-c	
  files	
  open	
  
Filehandle	
  Caching	
  
open_file_cache max=1000 inactive=5m;
open_file_cache_valid 60s;
open_file_cache_min_uses 5;
open_file_cache_errors off;
44 #Dynatrace
•  ngx_hbp_upstream_module	
  
Load	
  balancing	
  PHP	
  
upstream php_loadbalancer {
ip_hash;
server unix:/var/run/php5-fpm.sock weight=5;
server 192.168.56.12:7777 weight=2;
server 192.168.56.13:7777;
}
server {
listen 80;
root /home/www/test;
server_name test.hzvm01;
location / {
try_files $uri =405;
}
location ~ .php$ {
fastcgi_pass php_loadbalancer;
fastcgi_index index.php;
include fastcgi_params;
}
}
45 #Dynatrace
Load	
  balancing	
  PHP	
  
46 #Dynatrace
Load	
  balancing	
  /	
  Reverse	
  Proxy	
  
upstream backend {
ip_hash;
server 192.168.56.11 weight=5;
server 192.168.56.12 weight=2;
server 192.168.56.13;
}
server {
listen 80;
root /var/www/mysite.com/html;
server_name www.mysite.com;
location / {
try_files $uri =405;
proxy_pass http://backend;
}
}
47 #Dynatrace
Reverse	
  Proxy	
  /	
  Load	
  balancing	
  /	
  Caching	
  
proxy_cache_path /etc/nginx/cache keys_zone=APPKEY:10m;
proxy_cache_key "$host$request_uri$cookie_user";
proxy_cache_min_uses 5;
proxy_cache_methods GET HEAD;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
upstream backend {
ip_hash;
server 192.168.56.11 weight=5;
server 192.168.56.12 weight=2;
server 192.168.56.13;
}
server {
listen 80;
root /var/www/mysite.com/html;
server_name www.mysite.com;
proxy_cache APPKEY;
location / {
proxy_pass http://backend;
}
}
48 #Dynatrace
Performance	
  Monitoring	
  
49 #Dynatrace
End-­‐To-­‐End	
  Monitoring	
  
50 #Dynatrace
51 #Dynatrace
52 #Dynatrace
User	
  Experience	
  Management	
  
53 #Dynatrace
54 #Dynatrace
55 #Dynatrace
lessc	
  library	
  caused	
  
performance	
  hotspot	
  
56 #Dynatrace
3rd	
  party	
  content	
  
57 #Dynatrace
3rd	
  party	
  content	
  
58 #Dynatrace
59 #Dynatrace
• PHP	
  agent	
  since	
  DT	
  5.5	
  
• Nginx	
  agent	
  since	
  DT	
  6.0	
  
• 100%	
  transac-on	
  tracing	
  
• Process	
  monitoring	
  
• Auto-­‐Sensor	
  to	
  trace	
  slow	
  func-on/method	
  execu-ons	
  
• OOTB	
  Sensor	
  Packs	
  
• Custom	
  Sensor	
  Rules	
  
• Error	
  handling	
  
60 #Dynatrace
• Free	
  trial	
  license	
  for	
  30	
  days	
  
• Free	
  for	
  developers	
  on	
  local	
  machine	
  
Dynatrace	
  Free	
  Trial	
  
hbp://bit.ly/dbrial	
  
61 #Dynatrace
Thank You
harald.zeitlhofer@dynatrace.com	
  
@HZeitlhofer	
  
	
  
www.dynatrace.com	
  

Más contenido relacionado

La actualidad más candente

What is new in BIND 9.11?
What is new in BIND 9.11?What is new in BIND 9.11?
What is new in BIND 9.11?Men and Mice
 
Apache Httpd and TLS certificates validations
Apache Httpd and TLS certificates validationsApache Httpd and TLS certificates validations
Apache Httpd and TLS certificates validationsJean-Frederic Clere
 
HTTP/2, HTTP/3 and SSL/TLS State of the Art in Our Servers
HTTP/2, HTTP/3 and SSL/TLS State of the Art in Our ServersHTTP/2, HTTP/3 and SSL/TLS State of the Art in Our Servers
HTTP/2, HTTP/3 and SSL/TLS State of the Art in Our ServersJean-Frederic Clere
 
Devoxx Maroc 2015 HTTP 1, HTTP 2 and folks
Devoxx Maroc  2015 HTTP 1, HTTP 2 and folksDevoxx Maroc  2015 HTTP 1, HTTP 2 and folks
Devoxx Maroc 2015 HTTP 1, HTTP 2 and folksNicolas Martignole
 
Content Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX PlusContent Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX PlusKevin Jones
 
RIPE 71 and IETF 94 reports webinar
RIPE 71 and IETF 94 reports webinarRIPE 71 and IETF 94 reports webinar
RIPE 71 and IETF 94 reports webinarMen and Mice
 
Anton Moldovan "Building an efficient replication system for thousands of ter...
Anton Moldovan "Building an efficient replication system for thousands of ter...Anton Moldovan "Building an efficient replication system for thousands of ter...
Anton Moldovan "Building an efficient replication system for thousands of ter...Fwdays
 
Docker remote-api
Docker remote-apiDocker remote-api
Docker remote-apiEric Ahn
 
Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011Tatsuhiko Miyagawa
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magentoMathew Beane
 
Apache httpd 2.4: The Cloud Killer App
Apache httpd 2.4: The Cloud Killer AppApache httpd 2.4: The Cloud Killer App
Apache httpd 2.4: The Cloud Killer AppJim Jagielski
 
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기NAVER D2
 
Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5Kazuho Oku
 
HTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないときHTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないときKazuho Oku
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - DeploymentFabio Akita
 
Integrated Cache on Netscaler
Integrated Cache on NetscalerIntegrated Cache on Netscaler
Integrated Cache on NetscalerMark Hillick
 
Troubleshooting containerized triple o deployment
Troubleshooting containerized triple o deploymentTroubleshooting containerized triple o deployment
Troubleshooting containerized triple o deploymentSadique Puthen
 

La actualidad más candente (20)

What is new in BIND 9.11?
What is new in BIND 9.11?What is new in BIND 9.11?
What is new in BIND 9.11?
 
Apache Httpd and TLS certificates validations
Apache Httpd and TLS certificates validationsApache Httpd and TLS certificates validations
Apache Httpd and TLS certificates validations
 
HTTP/2, HTTP/3 and SSL/TLS State of the Art in Our Servers
HTTP/2, HTTP/3 and SSL/TLS State of the Art in Our ServersHTTP/2, HTTP/3 and SSL/TLS State of the Art in Our Servers
HTTP/2, HTTP/3 and SSL/TLS State of the Art in Our Servers
 
Devoxx Maroc 2015 HTTP 1, HTTP 2 and folks
Devoxx Maroc  2015 HTTP 1, HTTP 2 and folksDevoxx Maroc  2015 HTTP 1, HTTP 2 and folks
Devoxx Maroc 2015 HTTP 1, HTTP 2 and folks
 
Content Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX PlusContent Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX Plus
 
From a cluster to the Cloud
From a cluster to the CloudFrom a cluster to the Cloud
From a cluster to the Cloud
 
RIPE 71 and IETF 94 reports webinar
RIPE 71 and IETF 94 reports webinarRIPE 71 and IETF 94 reports webinar
RIPE 71 and IETF 94 reports webinar
 
Anton Moldovan "Building an efficient replication system for thousands of ter...
Anton Moldovan "Building an efficient replication system for thousands of ter...Anton Moldovan "Building an efficient replication system for thousands of ter...
Anton Moldovan "Building an efficient replication system for thousands of ter...
 
Docker remote-api
Docker remote-apiDocker remote-api
Docker remote-api
 
Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
Apache httpd 2.4: The Cloud Killer App
Apache httpd 2.4: The Cloud Killer AppApache httpd 2.4: The Cloud Killer App
Apache httpd 2.4: The Cloud Killer App
 
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
[Hello world 오픈세미나]varnish로 웹서버성능 향상시키기
 
Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5
 
HTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないときHTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないとき
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - Deployment
 
Integrated Cache on Netscaler
Integrated Cache on NetscalerIntegrated Cache on Netscaler
Integrated Cache on Netscaler
 
Troubleshooting containerized triple o deployment
Troubleshooting containerized triple o deploymentTroubleshooting containerized triple o deployment
Troubleshooting containerized triple o deployment
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 

Similar a Running PHP on nginx

10 Million hits a day with WordPress using a $15 VPS
10 Million hits a day  with WordPress using a $15 VPS10 Million hits a day  with WordPress using a $15 VPS
10 Million hits a day with WordPress using a $15 VPSPaolo Tonin
 
Nginx, PHP, Apache and Spelix
Nginx, PHP, Apache and SpelixNginx, PHP, Apache and Spelix
Nginx, PHP, Apache and SpelixHarald Zeitlhofer
 
Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confooCombell NV
 
Web Front End Performance
Web Front End PerformanceWeb Front End Performance
Web Front End PerformanceChris Love
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesOtto Kekäläinen
 
How to install and configure LEMP stack
How to install and configure LEMP stackHow to install and configure LEMP stack
How to install and configure LEMP stackRootGate
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXKevin Jones
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Combell NV
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Converting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaConverting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaDana Luther
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersSeravo
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Dana Luther
 
Php through the eyes of a hoster
Php through the eyes of a hosterPhp through the eyes of a hoster
Php through the eyes of a hosterCombell NV
 
Boost your website by running PHP on Nginx
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on NginxHarald Zeitlhofer
 
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OSSupercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OSCloudLinux
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Jeff Jones
 

Similar a Running PHP on nginx (20)

Running PHP on Nginx
Running PHP on NginxRunning PHP on Nginx
Running PHP on Nginx
 
10 Million hits a day with WordPress using a $15 VPS
10 Million hits a day  with WordPress using a $15 VPS10 Million hits a day  with WordPress using a $15 VPS
10 Million hits a day with WordPress using a $15 VPS
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
 
Nginx, PHP, Apache and Spelix
Nginx, PHP, Apache and SpelixNginx, PHP, Apache and Spelix
Nginx, PHP, Apache and Spelix
 
Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confoo
 
Web Front End Performance
Web Front End PerformanceWeb Front End Performance
Web Front End Performance
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themes
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
How to install and configure LEMP stack
How to install and configure LEMP stackHow to install and configure LEMP stack
How to install and configure LEMP stack
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11Php through the eyes of a hoster phpbnl11
Php through the eyes of a hoster phpbnl11
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Converting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaConverting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - Cascadia
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]
 
Php through the eyes of a hoster
Php through the eyes of a hosterPhp through the eyes of a hoster
Php through the eyes of a hoster
 
Boost your website by running PHP on Nginx
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on Nginx
 
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OSSupercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 

Más de Harald Zeitlhofer

Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!Harald Zeitlhofer
 
Running PHP on Nginx / PHP wgtn
Running PHP on Nginx / PHP wgtnRunning PHP on Nginx / PHP wgtn
Running PHP on Nginx / PHP wgtnHarald Zeitlhofer
 
PHP App Performance / Sydney PHP
PHP App Performance / Sydney PHPPHP App Performance / Sydney PHP
PHP App Performance / Sydney PHPHarald Zeitlhofer
 
Nginx performance monitoring with Dynatrace
Nginx performance monitoring with DynatraceNginx performance monitoring with Dynatrace
Nginx performance monitoring with DynatraceHarald Zeitlhofer
 
Performance optimisation - scaling a hobby project to serious business
Performance optimisation - scaling a hobby project to serious businessPerformance optimisation - scaling a hobby project to serious business
Performance optimisation - scaling a hobby project to serious businessHarald Zeitlhofer
 

Más de Harald Zeitlhofer (11)

Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!Slow Database in your PHP stack? Don't blame the DBA!
Slow Database in your PHP stack? Don't blame the DBA!
 
Scaling PHP web apps
Scaling PHP web appsScaling PHP web apps
Scaling PHP web apps
 
PHP and databases
PHP and databasesPHP and databases
PHP and databases
 
Improve Magento Performance
Improve Magento PerformanceImprove Magento Performance
Improve Magento Performance
 
Running PHP on Nginx / PHP wgtn
Running PHP on Nginx / PHP wgtnRunning PHP on Nginx / PHP wgtn
Running PHP on Nginx / PHP wgtn
 
PHP App Performance / Sydney PHP
PHP App Performance / Sydney PHPPHP App Performance / Sydney PHP
PHP App Performance / Sydney PHP
 
PHP application performance
PHP application performancePHP application performance
PHP application performance
 
PHP Application Performance
PHP Application PerformancePHP Application Performance
PHP Application Performance
 
Nginx performance monitoring with Dynatrace
Nginx performance monitoring with DynatraceNginx performance monitoring with Dynatrace
Nginx performance monitoring with Dynatrace
 
Nginx, PHP and Node.js
Nginx, PHP and Node.jsNginx, PHP and Node.js
Nginx, PHP and Node.js
 
Performance optimisation - scaling a hobby project to serious business
Performance optimisation - scaling a hobby project to serious businessPerformance optimisation - scaling a hobby project to serious business
Performance optimisation - scaling a hobby project to serious business
 

Último

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Último (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Running PHP on nginx

  • 1. 1 #Dynatrace Proper  configura-on  for  high  performance  websites   Harald  Zeitlhofer   April  2015     Boost  your  website  by  running   PHP  on  Nginx   @HZeitlhofer   harald.zeitlhofer@dynatrace.com    
  • 2. 2 #Dynatrace Fast  PHP  applica-ons  
  • 4. 4 #Dynatrace Tips and tricks for high performance websites
  • 7. 7 #Dynatrace PHP   run  modes   Apache  Module   –  tradi-onal  approach   –  used  for  most  PHP   environments   CGI   –  Command  Line  Interface  (CLI)   FastCGI  (PHP-­‐FPM)   –  PHP  applica-on  server   –  Run  mul-ple  PHP  worker   processes  to  serve  CGI  requests  
  • 8. 8 #Dynatrace Nginx   Lightweight  HTTP  server   Fast  especially  at  high  load   Event  based  request  handling   Open  Source  project  (BSD)     by  Igor  Sysoev   Nginx,  Inc.  founded  in  2011  
  • 9. 9 #Dynatrace Leading  among     top  10.000  websites  
  • 10. 10 #Dynatrace but I could call the FPM from Apache !
  • 11. 11 #Dynatrace it’s not only the FPM yes,  but  ...   it’s Nginx' event based processing that creates the performance advantage
  • 12. 12 #Dynatrace Apache can also be operated in an event mode !
  • 13. 13 #Dynatrace it’s not 100% event based... yes,  but  ...  
  • 14. 14 #Dynatrace prefork  mode   one  process  per  request     worker  mode   mul-ple  threads  per  process,   one  per  request     worker  event  mode   event  based  request  handling  
  • 15. 15 #Dynatrace • mod_php   • mod_fcgid   • mod_fastcgi     Integra-on   • ngx_h5p_fastcgi_modul  
  • 16. 16 #Dynatrace PHP-­‐FPM   FastCGI  Process  Manager       Available  since  5.3.3,  stable  since  5.4.1        
  • 17. 17 #Dynatrace • Installa-on     • Pool  configura-on   /etc/php5/fpm/pool.d/www.conf PHP-­‐FPM   [www] user = www-data group = www-data listen = 127.0.0.1:9000 # for Unix socket: unix:/var/run/php5-fpm.sock; root@hzvm01:/etc/nginx/sites-enabled# ps -ef | grep php root 6435 1 0 14:39 ? 00:00:32 php-fpm: master process (/etc/php5/fpm/php-fpm.conf) spelix 6439 6435 0 14:39 ? 00:00:00 php-fpm: pool batch spelix 6440 6435 0 14:39 ? 00:00:00 php-fpm: pool batch www-data 10576 6435 1 18:45 ? 00:00:48 php-fpm: pool www www-data 10920 6435 1 18:47 ? 00:00:47 php-fpm: pool www www-data 10927 6435 1 18:47 ? 00:00:46 php-fpm: pool www sudo apt-get install php5-fpm
  • 18. 18 #Dynatrace • Pool  configura-on   /etc/php5/fpm/pool.d/www.conf PHP-­‐FPM   [pool_name] ... pm = [dynamic/static] pm.max_children = 10 ;only used for dynamic: pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 pm.max_children      =  total  available  memory  /  memory  used  by  1  PHP  process  
  • 19. 19 #Dynatrace Nginx  and  PHP-­‐FPM   Integra-on  
  • 20. 20 #Dynatrace • /etc/nginx/nginx.conf       # max_clients = worker_processes * worker_connections worker_processes 8; # number of CPUs worker_rlimit_nofile 40000; events { worker_connections 1024; multi_accept on; }
  • 21. 21 #Dynatrace • Communica-on  via  sockets   •  TCP  vs  Unix   •  Unix  slightly  faster  when  used  on  localhost   •  Use  TCP  for  high  load   location ~* .php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } fastcgi_pass unix:/var/run/php5-fpm.sock;
  • 23. 23 #Dynatrace •  Sta-c  content  to  be  served  by  Nginx   •  Dynamic  requests  to  be  sent  to  PHP-­‐FPM   Integra-on   server { listen 80; root /var/www/test; index index.php index.html index.htm; server_name test.whateveryourdomain.is; location ~ .(html|js|css|gif|jpg|jpe|jpeg|png|bmp|tif|pdf|ico)$ { try_files $uri =404; } location / { try_files $uri $uri/ =404; } location ~* .php$ { fastcgi_index index.php; fastcgi_pass php; include fastcgi_params; } }
  • 24. 24 #Dynatrace hbp://www.mysite.com/news/browse/2014   è  to  be  handled  by  index.php   URL  rewrite   ... RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.+)$ index.php ...
  • 25. 25 #Dynatrace hbp://www.mysite.com/news/browse/2014   è  to  be  handled  by  index.php   URL  rewrite   upstream php { server unix:/var/run/php5-fpm.sock; } server { listen 80; root /var/www; index index.php index.html index.htm; server_name www.mysite.com; location / { try_files $uri $uri/ @missing; } location @missing { rewrite (.*) /index.php; } location ~ .php$ { fastcgi_index index.php; include fastcgi_params; fastcgi_pass php; } }
  • 26. 26 #Dynatrace using  Nginx/PHP-­‐FPM  there’s  a  beber  way:   URL  rewrite   upstream php { server unix:/var/run/php5-fpm.sock; } server { listen 80; root /var/www; index index.php index.html index.htm; server_name www.mysite.com; location /images { try_files $uri =404; } location /scripts { try_files $uri =404; } location / { fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /var/www/index.php; fastcgi_pass php; } } <?php $params = explode('/', $_SERVER["DOCUMENT_URI"]); ...
  • 27. 27 #Dynatrace • Easy  way  to  deploy  your  applica-on   • All  source  files  packed  into  one  *.phar  file   PHAR  –  PHP  Archives   location ~* .(php|phar)$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/myapp.phar; }
  • 28. 28 #Dynatrace PHAR  example   root@hzvm01:/var/www/app/src# ls -lrtR .: total 8 drwxrwxr-x 2 root root 4096 Oct 10 16:27 lib -rw-r--r-- 1 root root 27 Oct 10 16:27 index.php ./lib: total 4 -rw-r--r-- 1 root root 87 Oct 10 16:27 App.php root@hzvm01:/var/www/app/src# cat index.php <?php $app = new App(); ?> root@hzvm01:/var/www/app/src# cat lib/App.php <?php class App { function __construct() { echo "Starting Applicationn"; } }
  • 29. 29 #Dynatrace PHAR  example   location /myapp { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/myapp.phar; } root@hzvm01:/var/www/app# phar pack -f myapp.phar src lib/App.php index.php root@hzvm01:/var/www/app# l myapp.phar -rw-r--r-- 1 root root 6923 Oct 10 19:51 myapp.phar
  • 32. 32 #Dynatrace • Nginx  running  with  default  segngs   • Apache   •  AllowOverride  None   •  Mul--­‐process  mode  to  allow  usage  of  mod_php   Benchmarking  Nginx  vs  Apache  
  • 33. 33 #Dynatrace Sta-c  HTML,  10k  requests   0   1   2   3   4   5   6   7   8   9   100   500   1000   2000   Apache/2.4.9   nginx/1.1.19   concurrency   Total  response  -me  [sec]  
  • 35. 35 #Dynatrace • Part  of  the  Nginx  FastCGI  module   Nginx  FastCGI  cache   fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=APPKEY:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; location ~* .php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_cache APPKEY; fastcgi_cache_valid 200 60m; }
  • 38. 38 #Dynatrace Tes-ng  FastCGI  cache   <?php echo time()."n"; ?>
  • 39. 39 #Dynatrace • ngx_hbp_memcached_module   Full  page  cache  with  Nginx  and  Memcached   server { location / { set $memcached_key "$uri"; memcached_pass localhost:11211; error_page 404 502 504 = @fallback; } location @fallback { proxy_pass http://backend; } }
  • 40. 40 #Dynatrace • PHP     Full  page  cache  with  Nginx  and  Memcached   <?php ... function cachePage($content) { $c = new Memcached(); $c->addServer('localhost',11211); $c->set($_SERVER[”REQUEST_URI"], $content); } ... $content = $this->renderPage(); $this->cachePage($content); ... ?>
  • 41. 41 #Dynatrace PHP,  5k  requests,  concurrency  100   0   1   2   3   4   5   6   7   8   Apache+PHP   Nginx+PHP   Nginx+Memcached   <?php echo “Hello World”; ?>
  • 42. 42 #Dynatrace • set  HTTP  response  expires  header   Client  Side  Caching   location ~ .(html|js|css|gif|jpg|jpe|jpeg|png|bmp|tif|pdf|ico)$ { expires 90d; access_log off; error_log off; try_files $uri =404; }
  • 43. 43 #Dynatrace • keep  handlers  for  requested  sta-c  files  open   Filehandle  Caching   open_file_cache max=1000 inactive=5m; open_file_cache_valid 60s; open_file_cache_min_uses 5; open_file_cache_errors off;
  • 44. 44 #Dynatrace •  ngx_hbp_upstream_module   Load  balancing  PHP   upstream php_loadbalancer { ip_hash; server unix:/var/run/php5-fpm.sock weight=5; server 192.168.56.12:7777 weight=2; server 192.168.56.13:7777; } server { listen 80; root /home/www/test; server_name test.hzvm01; location / { try_files $uri =405; } location ~ .php$ { fastcgi_pass php_loadbalancer; fastcgi_index index.php; include fastcgi_params; } }
  • 46. 46 #Dynatrace Load  balancing  /  Reverse  Proxy   upstream backend { ip_hash; server 192.168.56.11 weight=5; server 192.168.56.12 weight=2; server 192.168.56.13; } server { listen 80; root /var/www/mysite.com/html; server_name www.mysite.com; location / { try_files $uri =405; proxy_pass http://backend; } }
  • 47. 47 #Dynatrace Reverse  Proxy  /  Load  balancing  /  Caching   proxy_cache_path /etc/nginx/cache keys_zone=APPKEY:10m; proxy_cache_key "$host$request_uri$cookie_user"; proxy_cache_min_uses 5; proxy_cache_methods GET HEAD; proxy_cache_valid 200 302 10m; proxy_cache_valid 404 1m; upstream backend { ip_hash; server 192.168.56.11 weight=5; server 192.168.56.12 weight=2; server 192.168.56.13; } server { listen 80; root /var/www/mysite.com/html; server_name www.mysite.com; proxy_cache APPKEY; location / { proxy_pass http://backend; } }
  • 55. 55 #Dynatrace lessc  library  caused   performance  hotspot  
  • 59. 59 #Dynatrace • PHP  agent  since  DT  5.5   • Nginx  agent  since  DT  6.0   • 100%  transac-on  tracing   • Process  monitoring   • Auto-­‐Sensor  to  trace  slow  func-on/method  execu-ons   • OOTB  Sensor  Packs   • Custom  Sensor  Rules   • Error  handling  
  • 60. 60 #Dynatrace • Free  trial  license  for  30  days   • Free  for  developers  on  local  machine   Dynatrace  Free  Trial   hbp://bit.ly/dbrial  
  • 61. 61 #Dynatrace Thank You harald.zeitlhofer@dynatrace.com   @HZeitlhofer     www.dynatrace.com