Outils pour utilisateurs

Outils du site


informatique:php:performance

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
informatique:php:performance [10/12/2009 15:31] cyrilleinformatique:php:performance [23/07/2016 13:49] (Version actuelle) – [Profiling] nalyser les données du profiler de XDebug avec webgrind cyrille
Ligne 1: Ligne 1:
 ====== PHP Performance ====== ====== PHP Performance ======
 +
 +Voir aussi:
 +  * [[/informatique/php/cache|/informatique/php/Cache]]
  
 ===== Articles ===== ===== Articles =====
  
   * [[http://php100.wordpress.com/2009/07/13/php-performance/|More on PHP performance]] by [[http://php100.wordpress.com/|Stanislav Malyshev (alias Stas)]] on 2009-07-13   * [[http://php100.wordpress.com/2009/07/13/php-performance/|More on PHP performance]] by [[http://php100.wordpress.com/|Stanislav Malyshev (alias Stas)]] on 2009-07-13
 +  * [[http://www.phpclasses.org/blog/post/66-More-defensive-programming-practices-to-survive-Web-site-traffic-peaks.html|More defensive programming practices to survive Web site traffic peaks]] by Manuel Lemos on 2007-05-29
 +
 +  * [[http://www.phpclasses.org/blog/post/117-PHP-compiler-performance.html|PHP compiler performance]] comparaison by Manuel Lemos on 2010-02-05
  
 ===== At developpment time ===== ===== At developpment time =====
Ligne 10: Ligne 16:
  
 Profile you code before you start optimizing it! Otherwise it would be like travelling around a foreign city with signs written in an unreadable language witout any map or GPS. You’ll probably get somewhere, but you wouldn’t have any idea where you are, where you should go and how far are you from the place you need to be. Profiling would allow you to know which parts of code are worth investing into and which aren’t. You can use [[http://www.zend.com/en/products/studio/|Zend Studio/Debugger]] or [[/informatique/php/XDebug|Xdebug]] for that. Profile you code before you start optimizing it! Otherwise it would be like travelling around a foreign city with signs written in an unreadable language witout any map or GPS. You’ll probably get somewhere, but you wouldn’t have any idea where you are, where you should go and how far are you from the place you need to be. Profiling would allow you to know which parts of code are worth investing into and which aren’t. You can use [[http://www.zend.com/en/products/studio/|Zend Studio/Debugger]] or [[/informatique/php/XDebug|Xdebug]] for that.
 +
 +  * https://docs.moodle.org/dev/Profiling_PHP
 +    * xdebug.profiler_enable_trigger = 1 with XDEBUG_PROFILE set in  GET/POST or COOKIE
 +    * ou xdebug.profiler_enable = 1
 +  * [[http://morefedora.blogspot.com/2008/05/profile-memory-usage-of-php-scripts.html|Profile memory usage of PHP scripts]] with xdebug
 +    * xdebug.auto_trace = On
 +    * xdebug.show_mem_delta = On
 +
 +Analyser les données du profiler de XDebug avec [[https://github.com/jokkedk/webgrind#readme|webgrind]].
  
 ==== Caching ==== ==== Caching ====
Ligne 19: Ligne 34:
 ==== Optimize your data ==== ==== Optimize your data ====
  
-Usually the most expensive places of the PHP application are where it accesses external data – namely, database or filesystem or network. Look hard into optimizing that – reduce number of queries, improve database structure, reduce filesystem accesses, try to bundle data to make one service call instead of several, etc. For more advanced in-depth look, use tools like strace (Unix) and Process Explorer (Windows) to look into system calls your script produces and think about ways to eliminate some of  them. You would not be able to eliminate all of them but each of them is a worthy target.+Usually the most expensive places of the PHP application are where it accesses external data – namely, database or file system or network. Look hard into optimizing that – reduce number of queries, improve database structure, reduce file system accesses, try to bundle data to make one service call instead of several, etc. For more advanced in-depth look, use tools like strace (Unix) and Process Explorer (Windows) to look into system calls your script produces and think about ways to eliminate some of  them. You would not be able to eliminate all of them but each of them is a worthy target.
  
 ==== Avoid extra notices/errors/etc ==== ==== Avoid extra notices/errors/etc ====
  
 Even suppressed errors have cost in PHP, so try and write your code so it would not produce notices, strict notices, warnings, etc. You may want to enable logging of all errors to examine that. Never enable displaying errors in production though – it will only lead to a major public embarrassment. Even suppressed errors have cost in PHP, so try and write your code so it would not produce notices, strict notices, warnings, etc. You may want to enable logging of all errors to examine that. Never enable displaying errors in production though – it will only lead to a major public embarrassment.
 +
 +==== Eviter PREG ====
 +
 +Utiliser preg_* seulement quand on ne peut pas faire autrement.
 +
 +  stripos('http://',$website) est 2 fois plus rapide que preg_match('/http:\/\//i',$website)
 +
 +  ctype_alnum() est 5 fois plus rapide que preg_match('/^\s*$/')
 +
 +  Casting "if($test==(int)$test)" est 5 fois plus rapide que preg_match('/^\d*$/')
  
 ===== At build time ===== ===== At build time =====
informatique/php/performance.1260455485.txt.gz · Dernière modification : 19/05/2012 00:15 (modification externe)

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki