SlideShare ist ein Scribd-Unternehmen logo
1 von 20
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 !

Weitere ähnliche Inhalte

Was ist angesagt?

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 GoChris McEniry
 
Code quality tools for dev
Code quality tools for devCode quality tools for dev
Code quality tools for devDeepu S Nath
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
Pragmatic plone projects
Pragmatic plone projectsPragmatic plone projects
Pragmatic plone projectsAndreas Jung
 
eZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipeseZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipesPaul 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.6Webline Infosoft P Ltd
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATIONkrutitrivedi
 
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 PHPJonathan Klein
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP ApplicationsPavan Kumar N
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPCAnthony Ferrara
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshopDamien 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 PHPShweta A
 
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 CrenshawEC-Council
 

Was ist angesagt? (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
 

Ähnlich wie PHP Profiling/performance

PHP language presentation
PHP language presentationPHP language presentation
PHP language presentationAnnujj Agrawaal
 
Securing Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep SharmaSecuring Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep SharmaOSSCube
 
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 vulnerabilitiesDefconRussia
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildwebLeo 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 confooCombell NV
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 
Getting Started With Xdebug
Getting Started With XdebugGetting Started With Xdebug
Getting Started With XdebugJeremy 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
 
Profiling php applications
Profiling php applicationsProfiling php applications
Profiling php applicationsJustin Carmony
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend frameworkAlan Seiden
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariJoseph 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 Systemssosorry
 
Orange@php conf
Orange@php confOrange@php conf
Orange@php confHash Lin
 
Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧Orange Tsai
 

Ähnlich wie 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 - 那些在滲透測試的小技巧
 

Kürzlich hochgeladen

定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Lucknow
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 

Kürzlich hochgeladen (20)

定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 

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

Hinweis der Redaktion

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