Upload
mark-brown
View
10.033
Download
5
Tags:
Embed Size (px)
DESCRIPTION
Mark Brown's talk at Dutch PHP Conference 2011 for tuning PHP on Windows and IIS.
Citation preview
Tips & Tricks
Tuning PHP
on Windows & IISMark Brown
Microsoft Corporation
@markjbrown
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 4.5 If !(User Cache)• MySQL Reverse-Lookup Bug• FastCGI Bug?
– Follow me on Twitter for updates
• Use mysql_pconnect()– Can cause issues using temp tables
• [mysqld] section of my.ini– Add skip-name-resolve
• Use 127.0.0.1 in code
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
DEMO
More Information
• http://php.iis.net• http://web.ms/php• http://windows.php.net
• Source Code and WCAT tool:• http://
dl.dropbox.com/u/23010264/PHP_Perf_Win-IIS.zip
Thank You
Questions?