Upload
mark-brown
View
3.958
Download
2
Tags:
Embed Size (px)
Citation preview
Tips & TricksTuning PHP
on Windows & IISMark Brown @markjbrown
Ruslan Yakushev @ruslany
http://ruslany.net
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
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
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!!!
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
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
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
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
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
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
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
More Information
• http://php.iis.net• http://web.ms/php• http://windows.php.net
Thank You
Questions?