PHP: How to install WinCache on IIS to improve performances

The most crippling bottleneck for many PHP-based software is almost always related to memory consumption. The PHP command interpreter does an excellent job for any low-traffic website, but when your WordPress blog (or Joomla! commercial website) jumps out of the unknown and really starts to hit the mark, you can bet you will soon face the issue: pages becoming slower, requests hanging out and often reaching the 503 - Service Unavailable or other timeout errors, and other stuff that will drive crazy your monitor tools like Yslow (if you don't use it yet, you better start now!), Analytics and so on

To drastically improve the performance of any high-traffic PHP website running under IIS you can consider installing one of the free caching PHP extension tools available: in this post we'll cover the Microsoft one, namely WinCache, which is included in all the base PHP installation packages for Windows since version 5.2. This neat extension grants a serious performance boost thanks to a five-level caching mechanism:

  • OPCode Cache: Caches the compiled bytecode of the most used scripts, so the system can avoid to perform the same identical task multiple times.
  • File Cache: Caches the php files by loading them in a shared memory block, so they can be easily accessed by all processes avoiding expensive IO/file operations.
  • Resolve File Path Cache: Stores the mappings between relative and absolute file paths, thereby reducing the number of path resolutions that the PHP engine has to perform when it needs to calculate the absolute file path from its relative-to-current-folder reference.
  • User Cache: Stores any PHP objects and variables built for each user to reuse them for subsequent requests. This can be used to improve performance of PHP scripts and to share the data across multiple PHP processes.
  • Session Cache: Stores the PHP session data in the shared memory cache: this avoid file system operations for reading and writing session data, which improves performance when large amount of data is stored in PHP session.

Installing WinCache is fairly easy. The first thing you need to do is to check whether the php_wincache.dll file is included in your PHP installation or not. This file is located in the /ext/ subfolder of your PHP installation folder. If it's not there, you can download it manually from the WinCache official website (just be sure to pick the file matching your PHP version), unpack it and copy the .dll file to the aforementioned folder.

Then you need to enable the WinCache extension to your PHP installation by adding the following two lines to your php.ini file, which is usually located in your PHP installation folder OR in the Windows root folder:

IMPORTANT: Before you do that you might want to check if the extension is already enabled by doing a quick text search for "php_wincache.dll" inside the file.

If you're using PHP Manager for IIS (which you really should) you could also install the WinCache extension directly from the PHP Manager GUI.

If you're NOT using PHP Manager for IIS and/or you have no idea of where your php.ini file actually is, you can easily track it by executing the phpinfo() command on your server (if you don't know how, just click here to download a sample script, put it on your server and execute it): as soon as you did that you can review your whole PHP configuration, which contains the full path of the currently Loaded Configuration File:

Loaded Configuration File

That same phpinfo() command can be also used to check whether the WinCache extension has been properly installed or not. If that's the case you will be able to see something like that by scrolling down a little:

Wincache configuration in PHPInfoIn most cases, like the screenshot above, the system will tell you that all the caches are currently disabled: this is perfectly normal, since we didn't activate any of them yet.

In order to do so we need to add some additional configuration settings to our php.ini file:

These settings are generally OK for most production environments. You can fine-tune them by taking a look to the WinCache reference guide, where you will find a detailed description of any possible configuration setting to adapt WinCache to your needs.

When you think you're done, save the php.ini file and restart IIS: you'll be able to check the results of your hard work by executing the phpinfo() command again:

PHPINFO: wincache enabled

That's about it: enjoy caching!

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

12 Comments on “PHP: How to install WinCache on IIS to improve performances”

  1. Pingback: PHP & WinCache: a GUI to display statistics and usage info - Ryadel.com
  2. I’ll right away snatch your rss feed as I can’t find your e-mail subscription hyperlink or newsletter service.
    Do you have any? Please permit me know in order that I may just subscribe.
    Thanks.

  3. Historically, green tea has been used by saints and people of
    oriental cultures to feel relaxed and rejuvenated.
    And you do not need to cut out foods with the latest diet fad.

    The biggest mistake that retailers make is the failure to prepare and present tea
    properly.

  4. Pingback: PHP lock and thread-sync using WinCache and/or APC
  5. Hello, Ryan.

    I was quite interested to come across your post about WordPress performance tuning in IIS.

    I followed your instructions and found the reference to [PHP_WINCACHE] in the php.ini file. I added the recommended [WinCache] settings to php.ini as well.

    Now, when I run phpinfo script I don’t see the Opcodecache anywhere, only File cache enabled.

    As your post was written in October 2014 and it was pertinent to PHP 5.x (I am on 7.0.9) I am wondering if there were any changes to WinCache implementation and what I see it normal or I probably need to do some more tweaking?
    In general, now 2.5 years after you made your very informative post how do we have to handle WinCache in 2017?

    Thanks very much in advance
    Ascar

    https://uploads.disquscdn.com/images/976418056af34347245da220448859ab43024bf2223ae9c46ba3dc7c8e656508.jpg

  6. Pingback: Powershell DSC – Installing PHP – PRJ702
  7. Hey Ryan,
    I have been searching the web now for a while with no luck. I tried this configuration on a windows server 2019 machine with no luck
    the wincache does not show up on the phpinfo page nor the wincache script..

    do you have another instruction around for an install on windows server 2019?

    1. Hi Joel,
      sure, first you need to install the extension:
      https://sourceforge.net/projects/wincache/

      and then you need to follow the “installation” instructions written here:
      https://www.php.net/manual/en/wincache.installation.php

      Windows Server 2019 has nothing to do with that, it’s just a matter of IIS version (up to v10) and PHP version (up to 7.3)

  8. Hey Ryan, thanks so much for the reply. the “install this extension” form iis takes me to another page with different modules and that extension is not there. at the bottom of the “install this extension” page i have downloaded the “5.6 version ” for the “5.6.40 php version” i currently have install on my machine.

    still with no luck..

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.