SlideShare a Scribd company logo
PHP Profiling/performance
PHP profiling/perfomance
Processing time,
Transmission time
CPU Bandwith
Memory
I/O
PHP profiling/perfomance
• Expected traffic
• Traffic growth
• Scalability means
• Evolutions to come…
Set the context
• Contextually : search engine, file generation,
task…
Establish the objectives
PHP profiling/perfomance
•Language
•Framework
•Libraries
•…
Adapt technologies
PHP profiling/perfomance
• Smart, structured code
• Lazy loading
• Static variables (singletons/registries)
• Cache
Code
• Autoloader
• Reduce and order include_path
• Client cache (HTTP headers Cache-Control, Expire)
• Avoid regexps
• …
Good practices
• Php.ini : realpath_cache_size
• Nginx : worker_processes, open_file_cache, multi_accept, keepalive, gzip
• Cache op-code
• Disable logs
Server configuration
PHP profiling/perfomance
• Ponctual inefficiencies/bottlenecks
detection
• Monitoring (analytics, alert tools)
• Take comparison points (before/after)
• Know when to stop
• Never rely on intuition!
Measure
PHP profiling/perfomance
Load tests
• ApacheBenchmark
• Siege
• Httperf
• …
Profiling
• Xdebug
• XHProf
• …
Measuring
tools
PHP profiling/perfomance
ApacheBenchmark
ab -n 50 -c 2 -v 1 -p 'post.txt' -T 'application/json'
-H 'Authorization: Bearer eyJ0eXAi.eyJpc3nYXJ.KznbYbc'
'http://api.gma.my/account/authenticate?alt=json&metadata
[foo]=Hello&metadata[bar]=World&metadata[random Val]=Ted'
> bench.txt
{
"application_key":"afaf770",
"email":"ndegardin@tribalnova.com",
"key":"ndegardin«
}
post.txt
PHP profiling/perfomance
…
Concurrency Level: 2
Time taken for tests: 25.704 seconds
Complete requests: 50
Failed requests: 44
(Connect: 0, Receive: 0, Length: 44, Exceptions: 0)
Write errors: 0
Non-2xx responses: 50
Total transferred: 2231974 bytes
Total POSTed: 28100
HTML transferred: 2220474 bytes
Requests per second: 1.95 [#/sec] (mean)
Time per request: 1028.176 [ms] (mean)
Time per request: 514.088 [ms] (mean, across all concurrent requests)
Transfer rate: 84.80 [Kbytes/sec] received
1.07 kb/s sent
85.86 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 704 1014 154.5 990 1693
Waiting: 704 1014 154.5 990 1693
Total: 705 1015 154.5 990 1693
…
bench.txt
PHP profiling/perfomance
• PHP profiling extension
• Developed by Facebook
• The basic version stores traces
• I diddn’t succeed in using the bundled
PHP/HTML app…
• With XHPROF, the profiling is triggered by
calling xhprof_enable(), xhprof_disable()
• Cool solution : auto_append_file,
auto_prepend_file in php.ini
XHProf
PHP profiling/perfomance
• Website http://xhprof.io
• Sources https://github.com/gajus/xhprof.io
• Profiling stored in database
• php.ini
• auto_append_file=/var/www/xhprofio/inc/append.php
• auto_prepend_file=/var/www/xhprofio/inc/prepend.php
• Not my recommandation
XHProf.io
PHP profiling/perfomance
• Sources https://github.com/sepehr/xhprof
• Profiling stored in database (one table « details »)
• Very good profiler
• php.ini
• auto_prepend_file=/var/www/xhprof/external/header.php
• auto_append_file=/var/www/xhprof/external/footer.php
• In CGI :
• activation by cookie _profile=1
• or by adding the parameter _profile=1 to the URL (adds the cookie,
then redirects)
• In CLI :
• auto_prepend/auto_append in/etc/php5/cli/php.ini
• activation by « export XHPROF_PROFILE=1 »
XHGUI
PHP profiling/perfomance
• Activate profiling by vhost in Apache
• Activate profiling by using a nginx/PHP-FPM pool :
/etc/php5/fpm/pool.d/www.conf :
• Activate profiling by vhost in nginx/PHP-FPM, in a
location section
XHProf notes
fastcgi_param PHP_ADMIN_VALUE
"auto_prepend_file=/var/www/xhprof/external/header.phpnauto_append_file=/var/
www/xhprof/external/footer.php";
php_admin_value auto_prepend_file "/var/www/xhprof/external/header.php"
php_admin_value auto_append_file "/var/www/xhprof/external/footer.php"
php_admin_value[auto_prepend_file] = /var/www/xhprofio/inc/prepend.php"
php_admin_value[auto_appendfile] = /var/www/xhprofio/inc/append.php"
PHP profiling/perfomance
• Web site http://xdebug.org/
• Developed by Derik Rethans
• PHP extension, now generally bundled with PHP
• Features :
• Debugging functions (time, calls, scream)
• Maximum nesting protection
• Enhanced stacktraces
• Remote debugging
• Profiling
• Code coverage
Xdebug
PHP profiling/perfomance
Xdebug notes about debugging
zend_extension=/usr/lib/php5/20090626/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
xdebug.remote_mode = req
xdebug.remote_host = 192.168.56.1
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = /var/log/xdebug
xdebug.profiler_output_name =
cachegrind.out.%H_%s_%R.xt
php.ini
PHP profiling/perfomance
• Prevent nginx from sending a gateway timeout (504) :
in /etc/nginx/nginx.conf, add
• Remote debug events triggered externally by setting a
XDEBUG_SESSION cookie and, if needed, mapping
paths (client/server) in your IDE
• Remote debug CLI scripts by running export
XDEBUG_CONFIG="idekey=netbeans-xdebug"and
setting php.ini xdebug.remote_host
Xdebug notes about debugging
fastcgi_read_timeout 3000;
keepalive_timeout 3000;
keepalive_requests 3000;
client_header_timeout 3000;
client_body_timeout 3000;
nginx.conf
PHP profiling/perfomance
• The traces are stored as files
• It often weights about 2Mo (be careful when forgetting it)
• Using a fixed name (without timestamp) in php.ini
xdebug.profiler.output_name allows a run script to erase the
previous one
• No official Xdebug trace extension, I suggest
cachegrind.out.[…].xt
• Profilers :
• WinCacheGrind (Windows) : somewhat simple
• WebGrind (Web) : « For quick’n’dirty optimizations it does the
job »
• KCacheGrind (KDE) : the best one
• PHPStorm : not really useful
Xdebug notes about profiling
PHP profiling/perfomance
• To run it under Windows, use KDE4Win
(package system similar to Cygwin’s one),
it should be in the « kdesdk » package.
Not available on all mirrors.
• Install GraphViz to enable drawing some
charts (and add its /bin directory the the
PATH)
• Check the Call Graph view!
kCacheGrind
PHP profiling/perfomance
• About different times :
• The wall time includes I/O (network latency, database
accesses, waiting for an user input…)
• The including time includes the children call
• The CPU exclusion time (self time in KCacheGrind) is the
more relevant value
• Switch between display formats :
• Percentage is better for comparing values
• Time is better for assessing values
• Tweaking script parameters (input configuration, number
of entries processed in database, number of iterations…)
may allow to observe different phenomena
Notes about profiling
Nicolas Degardin
ndegardin@tribalnova.com
Merci !

More Related Content

What's hot

Php extensions
Php extensionsPhp extensions
Php extensions
Elizabeth Smith
 
Django Documentation
Django DocumentationDjango Documentation
Django Documentation
Ying wei (Joe) Chou
 
OSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with GoOSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with Go
Chris McEniry
 
Code quality tools for dev
Code quality tools for devCode quality tools for dev
Code quality tools for dev
Deepu S Nath
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
Michael Pirnat
 
Anatomy of PHP Shells
Anatomy of PHP ShellsAnatomy of PHP Shells
Anatomy of PHP Shells
Vedran Krivokuca
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
Vibrant Technologies & Computers
 
Pragmatic plone projects
Pragmatic plone projectsPragmatic plone projects
Pragmatic plone projects
Andreas Jung
 
eZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipeseZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipes
Paul Borgermans
 
10 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.610 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.6
Webline Infosoft P Ltd
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
krutitrivedi
 
A content repository for your PHP application or CMS?
A content repository for your PHP application or CMS?A content repository for your PHP application or CMS?
A content repository for your PHP application or CMS?
Paul Borgermans
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
Jonathan Klein
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
Pavan Kumar N
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPC
Anthony Ferrara
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshop
Damien Seguy
 
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
Mark Hamstra
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
Shweta A
 
Hppg
HppgHppg
TakeDownCon Rocket City: WebShells by Adrian Crenshaw
TakeDownCon Rocket City: WebShells by Adrian CrenshawTakeDownCon Rocket City: WebShells by Adrian Crenshaw
TakeDownCon Rocket City: WebShells by Adrian Crenshaw
EC-Council
 

What's hot (20)

Php extensions
Php extensionsPhp extensions
Php extensions
 
Django Documentation
Django DocumentationDjango Documentation
Django Documentation
 
OSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with GoOSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with Go
 
Code quality tools for dev
Code quality tools for devCode quality tools for dev
Code quality tools for dev
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Anatomy of PHP Shells
Anatomy of PHP ShellsAnatomy of PHP Shells
Anatomy of PHP Shells
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
 
Pragmatic plone projects
Pragmatic plone projectsPragmatic plone projects
Pragmatic plone projects
 
eZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipeseZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipes
 
10 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.610 Most Important Features of New PHP 5.6
10 Most Important Features of New PHP 5.6
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
 
A content repository for your PHP application or CMS?
A content repository for your PHP application or CMS?A content repository for your PHP application or CMS?
A content repository for your PHP application or CMS?
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPC
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshop
 
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
 
Hppg
HppgHppg
Hppg
 
TakeDownCon Rocket City: WebShells by Adrian Crenshaw
TakeDownCon Rocket City: WebShells by Adrian CrenshawTakeDownCon Rocket City: WebShells by Adrian Crenshaw
TakeDownCon Rocket City: WebShells by Adrian Crenshaw
 

Similar to PHP Profiling/performance

PHP language presentation
PHP language presentationPHP language presentation
PHP language presentation
Annujj Agrawaal
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
Brian DeShong
 
Securing Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep SharmaSecuring Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep Sharma
OSSCube
 
Vorontsov, golovko ssrf attacks and sockets. smorgasbord of vulnerabilities
Vorontsov, golovko   ssrf attacks and sockets. smorgasbord of vulnerabilitiesVorontsov, golovko   ssrf attacks and sockets. smorgasbord of vulnerabilities
Vorontsov, golovko ssrf attacks and sockets. smorgasbord of vulnerabilities
DefconRussia
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
Leo Zhou
 
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
Combell NV
 
Basics PHP
Basics PHPBasics PHP
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
Ben Ramsey
 
Nginx pres
Nginx presNginx pres
Nginx pres
James Fuller
 
Getting Started With Xdebug
Getting Started With XdebugGetting Started With Xdebug
Getting Started With Xdebug
Jeremy Ward
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
Php go vrooom!
Php go vrooom!Php go vrooom!
Php go vrooom!
Elizabeth Smith
 
Php
PhpPhp
Profiling php applications
Profiling php applicationsProfiling php applications
Profiling php applications
Justin Carmony
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
Alan Seiden
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
Joseph Scott
 
(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems
sosorry
 
Caching
CachingCaching
Caching
Aaron Scherer
 
Orange@php conf
Orange@php confOrange@php conf
Orange@php conf
Hash Lin
 
Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧
Orange Tsai
 

Similar to PHP Profiling/performance (20)

PHP language presentation
PHP language presentationPHP language presentation
PHP language presentation
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Securing Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep SharmaSecuring Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep Sharma
 
Vorontsov, golovko ssrf attacks and sockets. smorgasbord of vulnerabilities
Vorontsov, golovko   ssrf attacks and sockets. smorgasbord of vulnerabilitiesVorontsov, golovko   ssrf attacks and sockets. smorgasbord of vulnerabilities
Vorontsov, golovko ssrf attacks and sockets. smorgasbord of vulnerabilities
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
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
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
Getting Started With Xdebug
Getting Started With XdebugGetting Started With Xdebug
Getting Started With Xdebug
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
Php go vrooom!
Php go vrooom!Php go vrooom!
Php go vrooom!
 
Php
PhpPhp
Php
 
Profiling php applications
Profiling php applicationsProfiling php applications
Profiling php applications
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems(phpconftw2012) PHP as a Middleware in Embedded Systems
(phpconftw2012) PHP as a Middleware in Embedded Systems
 
Caching
CachingCaching
Caching
 
Orange@php conf
Orange@php confOrange@php conf
Orange@php conf
 
Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧
 

Recently uploaded

办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
xjq03c34
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
wolfsoftcompanyco
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
zoowe
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
Laura Szabó
 
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
bseovas
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
uehowe
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
cuobya
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
SEO Article Boost
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
zyfovom
 
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
bseovas
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
cuobya
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
davidjhones387
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
AanSulistiyo
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Florence Consulting
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
hackersuli
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
saathvikreddy2003
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
Trish Parr
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
uehowe
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
ysasp1
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
fovkoyb
 

Recently uploaded (20)

办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
 
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
留学学历(UoA毕业证)奥克兰大学毕业证成绩单官方原版办理
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
 
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
 

PHP Profiling/performance

  • 3. PHP profiling/perfomance • Expected traffic • Traffic growth • Scalability means • Evolutions to come… Set the context • Contextually : search engine, file generation, task… Establish the objectives
  • 5. PHP profiling/perfomance • Smart, structured code • Lazy loading • Static variables (singletons/registries) • Cache Code • Autoloader • Reduce and order include_path • Client cache (HTTP headers Cache-Control, Expire) • Avoid regexps • … Good practices • Php.ini : realpath_cache_size • Nginx : worker_processes, open_file_cache, multi_accept, keepalive, gzip • Cache op-code • Disable logs Server configuration
  • 6. PHP profiling/perfomance • Ponctual inefficiencies/bottlenecks detection • Monitoring (analytics, alert tools) • Take comparison points (before/after) • Know when to stop • Never rely on intuition! Measure
  • 7. PHP profiling/perfomance Load tests • ApacheBenchmark • Siege • Httperf • … Profiling • Xdebug • XHProf • … Measuring tools
  • 8. PHP profiling/perfomance ApacheBenchmark ab -n 50 -c 2 -v 1 -p 'post.txt' -T 'application/json' -H 'Authorization: Bearer eyJ0eXAi.eyJpc3nYXJ.KznbYbc' 'http://api.gma.my/account/authenticate?alt=json&metadata [foo]=Hello&metadata[bar]=World&metadata[random Val]=Ted' > bench.txt { "application_key":"afaf770", "email":"ndegardin@tribalnova.com", "key":"ndegardin« } post.txt
  • 9. PHP profiling/perfomance … Concurrency Level: 2 Time taken for tests: 25.704 seconds Complete requests: 50 Failed requests: 44 (Connect: 0, Receive: 0, Length: 44, Exceptions: 0) Write errors: 0 Non-2xx responses: 50 Total transferred: 2231974 bytes Total POSTed: 28100 HTML transferred: 2220474 bytes Requests per second: 1.95 [#/sec] (mean) Time per request: 1028.176 [ms] (mean) Time per request: 514.088 [ms] (mean, across all concurrent requests) Transfer rate: 84.80 [Kbytes/sec] received 1.07 kb/s sent 85.86 kb/s total Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 0 Processing: 704 1014 154.5 990 1693 Waiting: 704 1014 154.5 990 1693 Total: 705 1015 154.5 990 1693 … bench.txt
  • 10. PHP profiling/perfomance • PHP profiling extension • Developed by Facebook • The basic version stores traces • I diddn’t succeed in using the bundled PHP/HTML app… • With XHPROF, the profiling is triggered by calling xhprof_enable(), xhprof_disable() • Cool solution : auto_append_file, auto_prepend_file in php.ini XHProf
  • 11. PHP profiling/perfomance • Website http://xhprof.io • Sources https://github.com/gajus/xhprof.io • Profiling stored in database • php.ini • auto_append_file=/var/www/xhprofio/inc/append.php • auto_prepend_file=/var/www/xhprofio/inc/prepend.php • Not my recommandation XHProf.io
  • 12. PHP profiling/perfomance • Sources https://github.com/sepehr/xhprof • Profiling stored in database (one table « details ») • Very good profiler • php.ini • auto_prepend_file=/var/www/xhprof/external/header.php • auto_append_file=/var/www/xhprof/external/footer.php • In CGI : • activation by cookie _profile=1 • or by adding the parameter _profile=1 to the URL (adds the cookie, then redirects) • In CLI : • auto_prepend/auto_append in/etc/php5/cli/php.ini • activation by « export XHPROF_PROFILE=1 » XHGUI
  • 13. PHP profiling/perfomance • Activate profiling by vhost in Apache • Activate profiling by using a nginx/PHP-FPM pool : /etc/php5/fpm/pool.d/www.conf : • Activate profiling by vhost in nginx/PHP-FPM, in a location section XHProf notes fastcgi_param PHP_ADMIN_VALUE "auto_prepend_file=/var/www/xhprof/external/header.phpnauto_append_file=/var/ www/xhprof/external/footer.php"; php_admin_value auto_prepend_file "/var/www/xhprof/external/header.php" php_admin_value auto_append_file "/var/www/xhprof/external/footer.php" php_admin_value[auto_prepend_file] = /var/www/xhprofio/inc/prepend.php" php_admin_value[auto_appendfile] = /var/www/xhprofio/inc/append.php"
  • 14. PHP profiling/perfomance • Web site http://xdebug.org/ • Developed by Derik Rethans • PHP extension, now generally bundled with PHP • Features : • Debugging functions (time, calls, scream) • Maximum nesting protection • Enhanced stacktraces • Remote debugging • Profiling • Code coverage Xdebug
  • 15. PHP profiling/perfomance Xdebug notes about debugging zend_extension=/usr/lib/php5/20090626/xdebug.so xdebug.remote_enable = 1 xdebug.remote_handler = "dbgp" xdebug.remote_port = 9000 xdebug.remote_mode = req xdebug.remote_host = 192.168.56.1 xdebug.profiler_enable = 1 xdebug.profiler_output_dir = /var/log/xdebug xdebug.profiler_output_name = cachegrind.out.%H_%s_%R.xt php.ini
  • 16. PHP profiling/perfomance • Prevent nginx from sending a gateway timeout (504) : in /etc/nginx/nginx.conf, add • Remote debug events triggered externally by setting a XDEBUG_SESSION cookie and, if needed, mapping paths (client/server) in your IDE • Remote debug CLI scripts by running export XDEBUG_CONFIG="idekey=netbeans-xdebug"and setting php.ini xdebug.remote_host Xdebug notes about debugging fastcgi_read_timeout 3000; keepalive_timeout 3000; keepalive_requests 3000; client_header_timeout 3000; client_body_timeout 3000; nginx.conf
  • 17. PHP profiling/perfomance • The traces are stored as files • It often weights about 2Mo (be careful when forgetting it) • Using a fixed name (without timestamp) in php.ini xdebug.profiler.output_name allows a run script to erase the previous one • No official Xdebug trace extension, I suggest cachegrind.out.[…].xt • Profilers : • WinCacheGrind (Windows) : somewhat simple • WebGrind (Web) : « For quick’n’dirty optimizations it does the job » • KCacheGrind (KDE) : the best one • PHPStorm : not really useful Xdebug notes about profiling
  • 18. PHP profiling/perfomance • To run it under Windows, use KDE4Win (package system similar to Cygwin’s one), it should be in the « kdesdk » package. Not available on all mirrors. • Install GraphViz to enable drawing some charts (and add its /bin directory the the PATH) • Check the Call Graph view! kCacheGrind
  • 19. PHP profiling/perfomance • About different times : • The wall time includes I/O (network latency, database accesses, waiting for an user input…) • The including time includes the children call • The CPU exclusion time (self time in KCacheGrind) is the more relevant value • Switch between display formats : • Percentage is better for comparing values • Time is better for assessing values • Tweaking script parameters (input configuration, number of entries processed in database, number of iterations…) may allow to observe different phenomena Notes about profiling

Editor's Notes

  1. .
  2. .
  3. .
  4. .
  5. .
  6. .
  7. .
  8. .
  9. .
  10. .
  11. .
  12. .
  13. .
  14. .
  15. .
  16. .
  17. .
  18. .