Top Banner
Tips & Tricks Tuning PHP on Windows & IIS Mark Brown Microsoft Corporation [email protected] @markjbrown
13

Tuning PHP for Windows & IIS

May 13, 2015

Download

Technology

Mark Brown

Mark Brown's talk at Dutch PHP Conference 2011 for tuning PHP on Windows and IIS.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tuning PHP for Windows & IIS

Tips & Tricks

Tuning PHP

on Windows & IISMark Brown

Microsoft Corporation

[email protected]

@markjbrown

Page 2: Tuning PHP for Windows & 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: Tuning PHP for Windows & 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: Tuning PHP for Windows & 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: Tuning PHP for Windows & 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: Tuning PHP for Windows & IIS

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

Page 7: Tuning PHP for Windows & 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 8: Tuning PHP for Windows & 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 9: Tuning PHP for Windows & 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 10: Tuning PHP for Windows & 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 11: Tuning PHP for Windows & IIS

DEMO

Page 12: Tuning PHP for Windows & IIS

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

Page 13: Tuning PHP for Windows & IIS

Thank You

Questions?