php perf tuning tips for win/iis

13
Tips & Tricks Tuning PHP on Windows & IIS Mark Brown @markjbrown [email protected] Ruslan Yakushev @ruslany [email protected] http ://ruslany.net

Upload: mark-brown

Post on 13-May-2015

3.958 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: PHP Perf Tuning Tips for Win/IIS

Tips & TricksTuning PHP

on Windows & IISMark Brown @markjbrown

[email protected]

Ruslan Yakushev @ruslany

[email protected]

http://ruslany.net

Page 2: PHP Perf Tuning Tips for Win/IIS

Tip #1 – Use IIS 7• PHP on IIS6 and Prior

– CGI – Slow as hell (1 request = 1 process)– ISAPI – Fast but unstable (mixed threading)

• IIS 7– Blew up IIS6– Modular Architecture– Default Minimum Installation– Streamlined Processing Pipeline– Uses FastCGI to handle PHP requests

• FastCGI now available for IIS 6

Page 3: PHP Perf Tuning Tips for Win/IIS

Tip #2 – Use Fast CGI• Uses an App Pool to process requests

– No CreateProc() for each Request!!!

• App Pool Size is configurable– Adjust AppPoolSize according to load to

maximize response time

• Automatic Tuning Capability– Set AppPoolSize = 0– Memory, Context Switches, CPU

• Auto Tuning useful if hosting many sites on same IIS server– Better density, site only uses resources it needs

Page 4: PHP Perf Tuning Tips for Win/IIS

Tip #3 – Use PHP 5.3• Feature & Security parity• Faster File IO on network shares• Win32 Codebase, not POSIX• New Windows build scripts• Compiled with VC9 vs. VC6

– Compile yourself to optimize further

• Non-Thread Safe binary for Windows– No NTS checks

• Make sure your extensions are NTS too!!!

Page 5: PHP Perf Tuning Tips for Win/IIS

Tip #4 – Use WinCache• Boost your speed with no code changes• Opcode Cache• File Cache

– Stores files in memory

• Relative File Path Cache– Helpful for shared or NFS storage

• Session Cache – Enable in php.ini

• User Data Cache– Store Data in memory– APC interface

Page 6: PHP Perf Tuning Tips for Win/IIS

Tip #5 – Config Proc Recycling• Don’t allow native PHP to do it.

• Allow FastCGI to manage PHP process recycling on IIS.

• Set instanceMaxRequests <= to PHP_FCGI_MAX_REQUESTS

• Default is 10K requests

Page 7: PHP Perf Tuning Tips for Win/IIS

Tip #6 –Per-Site PHP Config• Only for PHP 5.3• Configure IIS to have unique PHP config

for each site on server.– Eg. Photo upload site, vs long running scripts

• Php.ini file website overrides– Insert at the end of php.ini– [PATH=C:/inetpub/website1.com/]

max_execution_time = 300 – [PATH=C:/inetpub/website2.com/]

upload_max_filesize = 12M

Page 8: PHP Perf Tuning Tips for Win/IIS

Tip #7 – Use IIS Output Cache• Use for Semi-Dynamic Content

– Product pages, etc.

• User Mode Caching– Cached in IIS7 Worker Process

• Authentication and Authorization• varyByHeaders attribute • varyByQuerystring attribute

• Kernel Mode Caching– Cached in HTTP.SYS, a kernel mode driver– Much faster but lacks features that must

execute in Worker Process

Page 9: PHP Perf Tuning Tips for Win/IIS

Tip #8 – Fine Tuning Tips

• Set Default Document (index.php)• Remove unused services & modules• Minimize Logging• Use HTTP Keep-Alives• Use HTTP Compression

– Static & Dynamic

Page 10: PHP Perf Tuning Tips for Win/IIS

Tip #9 – Scale Out

• Application Request Router & Web Farm Framework (IIS Modules)– Reverse Proxy– Disk-based Caching– Platform Provisioning

• PHP, Drivers, etc.– Application Provisioning

• Your site

Page 11: PHP Perf Tuning Tips for Win/IIS

Tip #9 – Contributions

• Joomla!– Leverage WinCache in JCacheStorage

• WordPress– WinCache Object Cache– W3 Total Cache– Azure Storage Plugin

• Drupal– Drupal WinCache Module (in progress)

• Futures– Full docs on setup/config/tune for high scale

Page 12: PHP Perf Tuning Tips for Win/IIS

More Information

• http://php.iis.net• http://web.ms/php• http://windows.php.net

Page 13: PHP Perf Tuning Tips for Win/IIS

Thank You

Questions?