Your SlideShare is downloading. ×
0
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Php performance
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Php performance

4,176

Published on

PPT for PHP coding optimization and LAMP optimization

PPT for PHP coding optimization and LAMP optimization

Published in: Technology
1 Comment
12 Likes
Statistics
Notes
  • Thank you very much! php is my favorite, and your presentation helps much! :)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
4,176
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
119
Comments
1
Likes
12
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PHP Performance laruence [email_address] http://www.laruence.com/ 14-May-2011
  • 2. Goals
    • Reduce file IO
    • Less request
    • Save bandwidth
    • Make PHP faster
  • 3. Compiler Optimization
    • Compile PHP with –O3 flag
  • 4. WebServer
    • Apache
    • Nginx
    • Lighttpd
  • 5. Apache Optimizations
    • DirectoryIndex
    • AllowOverride
    • Options FollowSymLinks
    • Deny Allow
    • HostnameLookups
    • Keepalive
    • Log
  • 6. Output Optimizations
    • Output
    • ob_start
    • output_buffer
    • sendBufferSize
  • 7. Reduce Request
    • Use Css instead of style
    • Minifiy Javascript/Css
    • Merge Javascript/Css
    • Css sprite
  • 8. 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
  • 9. PHP Parse Cycle
    • compile_file
    • execute
  • 10. Merge Include
    • Reduce Opcode
    • Reduce File IO
  • 11. Opcode Cache
    • apc
    • eaccelerator
  • 12. Coding Optimization
  • 13. Prefer Use Static Methods
      • <?php
      • class Test {
      • public function a() {
      • }
      • public static function b() { }
      • }
      • ?>
    • 1:4
  • 14. Avoid Magic
    • __set
    • __get
    • __call
  • 15. Avoid Function calls
    • time() - $_SERVER[REQUEST_TIME]
    • phpversion() - PHP_VERSION
    • get_class() - __CLASS__
    • is_null() - NULL ===
    • strlen($str) == 5 – isset($str{5})
    • print() - echo
  • 16. Use Include instead of Include_once
    • 1 hash lookup
  • 17. @ is evil
    • @func()
    • $old = ini_set(“error_reporting”, 0);
    • func();
    • ini_set(“error_reporting”, $old);
  • 18. 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
  • 19. 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;)  
    • ?>
  • 20. Do not mis-use Constants
    • <?php
    • $array = array(“foo” => “bar”);
    • echo $array[foo]
    • ?>
    • Try constant
    • E_NOTICE
    • Create Tmp String
    • 1:7.5
  • 21. 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++) {}
  • 22. 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;
    • ?>
  • 23. 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() {}
    • }
  • 24. Shorten names
    • $product_car_price_in_doller
    • Function getTheUserFamilyAdress
    • Class PersonWhoHaveGun
  • 25. Use PHP’s functions
    • Internal Functions
    • Pcel Extensions
    • Pear
  • 26. Any Other ideas?
  • 27. Execute Method
    • Call
    • Swith
    • Goto
  • 28. Contents Cache
    • File
    • Session
    • Memecache
    • Expire time
  • 29. Use PHP Extension
    • C
    • Avoid Compile
    • Avoid Zend VM
  • 30. Profiling & Benchmarking
    • WebServer
      • ab
      • http_load
    • PHP
      • apd
      • xdebug
    • Mysql
      • explain
      • profile
  • 31. Q&A

×