Php performance
Upcoming SlideShare
Loading in...5
×
 

Php performance

on

  • 4,182 views

PPT for PHP coding optimization and LAMP optimization

PPT for PHP coding optimization and LAMP optimization

Statistics

Views

Total Views
4,182
Views on SlideShare
2,834
Embed Views
1,348

Actions

Likes
11
Downloads
114
Comments
0

14 Embeds 1,348

http://www.laruence.com 1108
http://blogread.cn 186
http://www.linkedin.com 13
url_unknown 11
http://xianguo.com 9
http://zhuaxia.com 5
http://www.cnblogs.com 4
http://www.zhuaxia.com 3
http://www.blogread.cn 2
https://www.linkedin.com 2
http://www.slideshare.net 2
https://translate.googleusercontent.com 1
http://www.techgig.com 1
http://geek99.tk 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Php performance Php performance Presentation Transcript

  • PHP Performance laruence [email_address] http://www.laruence.com/ 14-May-2011
  • Goals
    • Reduce file IO
    • Less request
    • Save bandwidth
    • Make PHP faster
  • Compiler Optimization
    • Compile PHP with –O3 flag
  • WebServer
    • Apache
    • Nginx
    • Lighttpd
  • Apache Optimizations
    • DirectoryIndex
    • AllowOverride
    • Options FollowSymLinks
    • Deny Allow
    • HostnameLookups
    • Keepalive
    • Log
  • Output Optimizations
    • Output
    • ob_start
    • output_buffer
    • sendBufferSize
  • Reduce Request
    • Use Css instead of style
    • Minifiy Javascript/Css
    • Merge Javascript/Css
    • Css sprite
  • Save Bandwidth
    • Freedomain Cookie
    • strip blank/comment in html
    • strip blank/comment in javascript/css
    • expire time for static content
    • compress content
      • Apache mod_gizp/mod_deflate
      • PHP zlib.output_compress
  • PHP Parse Cycle
    • compile_file
    • execute
  • Merge Include
    • Reduce Opcode
    • Reduce File IO
  • Opcode Cache
    • apc
    • eaccelerator
  • Coding Optimization
  • Prefer Use Static Methods
      • <?php
      • class Test {
      • public function a() {
      • }
      • public static function b() { }
      • }
      • ?>
    • 1:4
  • Avoid Magic
    • __set
    • __get
    • __call
  • Avoid Function calls
    • time() - $_SERVER[REQUEST_TIME]
    • phpversion() - PHP_VERSION
    • get_class() - __CLASS__
    • is_null() - NULL ===
    • strlen($str) == 5 – isset($str{5})
    • print() - echo
  • Use Include instead of Include_once
    • 1 hash lookup
  • @ is evil
    • @func()
    • $old = ini_set(“error_reporting”, 0);
    • func();
    • ini_set(“error_reporting”, $old);
  • Less memory usage
    • Use non-capturing Regex
      • preg_replace('&quot;/(?:n|t|rn|s)+/&quot;', ' ', $origtext );
    • avoid tmp variable
      • strncmp(PHP_OS, 'WIN', 3)
      • substr(PHP_OS, 0, 3) == 'WIN‘
    • unset variable after use
  • PCRE is slow
    • <?php
    • preg_replace( &quot;/n/&quot;, &quot;n&quot;, $text);
    • str_replace( &quot;/n/&quot;, &quot;n&quot;, $text);
    • preg_match(“/^foo_/i&quot;, &quot;FoO_&quot;)
    • !strncasecmp(&quot;foo_&quot;, &quot;FoO_&quot;, 4)
    • preg_match(“/[a8f9]/&quot;, &quot;sometext&quot;)
    • strpbrk(&quot;a8f9&quot;, &quot;sometext&quot;)
    • preg_match(&quot;!string!i&quot;, &quot;text&quot;) stripos(&quot;text&quot;, &quot;string&quot;)  
    • ?>
  • Do not mis-use Constants
    • <?php
    • $array = array(“foo” => “bar”);
    • echo $array[foo]
    • ?>
    • Try constant
    • E_NOTICE
    • Create Tmp String
    • 1:7.5
  • Do not multi-call function in for loop
    • <?php
    • for ($i=0; $i < count($array); $i++) {}
    • ?>
    • Instead
    • <?php
    • for ($i=0, $j=count($array); $i<$j; $i++) {}
  • Use Reference
    • <?php
    • $a[1][2] = array();
    • for($i = 0; $i < 10; $i++)
    • $a[1][2][$i] = $i;
    • ?>
    • Instead
    • <?php
    • $ref =& $a[1][2];
    • for($i = 0; $i < 10; $i++)
    • $ref[$i] = $i;
    • ?>
  • Do Work for PHP
    • Use full path in require/include
      • Inlucde “2.php”
      • Include “/home/huixinchen/phpsrc/2.php”
    • Less include path
    • Use instant instead of variable
    • <?php
    • class test {
    • public static function instance() { return new self();
    • } private function __construct() {}
    • }
  • Shorten names
    • $product_car_price_in_doller
    • Function getTheUserFamilyAdress
    • Class PersonWhoHaveGun
  • Use PHP’s functions
    • Internal Functions
    • Pcel Extensions
    • Pear
  • Any Other ideas?
  • Execute Method
    • Call
    • Swith
    • Goto
  • Contents Cache
    • File
    • Session
    • Memecache
    • Expire time
  • Use PHP Extension
    • C
    • Avoid Compile
    • Avoid Zend VM
  • Profiling & Benchmarking
    • WebServer
      • ab
      • http_load
    • PHP
      • apd
      • xdebug
    • Mysql
      • explain
      • profile
  • Q&A