Windows cache extension for php

Overview

Windows Cache Extension for PHP is a PHP accelerator that is used to increase the speed of PHP applications running on Windows and Windows Server. Once the Windows Cache Extension for PHP is enabled and loaded by the PHP engine, PHP applications can take advantage of the functionality without any code modifications.

Increase PHP application performance on Windows by caching PHP bytecode in memory

Windows Cache Extension for PHP stores the PHP bytecode, the compiled version of the PHP script, in memory making it available when subsequent executions of the same script are needed helping to increase the overall PHP application performance. The use of Windows Cache Extension for PHP allows the PHP bytecode to be generated only once and to be reused each time the same PHP script is executed.

Reduce file system I/O overhead by caching the PHP scripts in memory

Windows Cache Extension for PHP helps to reduce the latency of file operations when PHP scripts are stored on remote UNC file shares. Windows Cache Extension for PHP includes a file system cache that is used to store the content of the PHP script files in shared memory, which reduces the amount of file system operations performed by PHP engine.

Leverage the User Cache API’s to further improve the execution speed of PHP scripts

Windows Cache Extension provides user cache API’s, that can be used by PHP scripts to store PHP objects and variables in shared memory. This way PHP scripts may improve the execution speed by storing processed data in the cache and then using it in subsequent requests instead of re-creating the data on every request.

Avoid redundant mapping for absolute paths by using relative file path cache

Windows Cache Extension for PHP caches the relation between relative and absolute file paths, reducing the number of relative path resolutions performed by the PHP engine. PHP applications that use many relative paths would perform faster given the conversion to absolute paths is performed only once.

Features

  • PHP 5.2, PHP 5.3, PHP 5.4, PHP 5.5, PHP 5.6, PHP 7.0 and PHP 7.1 support
  • Configurable file cache
  • Configurable PHP opcode cache
  • User Cache API’s
  • File change notification support
  • WinCache handler for PHP sessions
  • Relative file path cache
  • PHP functions to obtain information about the cache status

Download WinCache

  • WinCache 1.1 for PHP 5.2 — x86 installer
  • WinCache 1.3 for PHP 5.3 — x86 installer
  • WinCache 1.3 for PHP 5.4 — x86 installer
  • WinCache 1.3 for PHP 5.5 — x86 installer
  • WinCache 1.3 for PHP 5.6 — x86 installer
  • WinCache 2.0 for PHP 7.0 — x86 installer | x64 installer
  • WinCache 2.0 for PHP 7.1 — x86 installer | x64 installer
  • WinCache Source Code

Windows Cache Extension for PHP is a PHP accelerator that is used to increase the speed of
PHP applications running on Windows and Windows Server. Once the Windows Cache Extension for
PHP is enabled and loaded by the PHP engine, PHP applications can take advantage of the
functionality without any code modifications.

The Windows Cache Extension includes 5 different types of caches. The following describes
the purpose of each cache type and the benefits it provides.

  • PHP Opcode Cache — PHP is a script processing engine, which reads
    an input stream of data that contains text and/or PHP instructions and produces another
    stream of data, most commonly in the HTML format. This means that on a web server the
    PHP engine reads, parses, compiles and executes a PHP script each time that it is requested
    by a Web client. The reading, parsing and compilation operations put additional load on the
    web server’s CPU and file system and thus affect the overall performance of a PHP web application.
    The PHP bytecode (opcode) cache is used to store the compiled script bytecode in shared memory so
    that it can be re-used by PHP engine for subsequent executions of the same script.

    Support for opcode caching was removed in Wincache 2.0.0, all users who
    wish to have an opcache should use the OPcache extension
    that is included with PHP.

  • File Cache — Even with the PHP opcode cache enabled, the PHP engine
    has to accesses the script files on a file system. When PHP scripts are stored on a remote
    UNC file share, the file operations introduce a significant performance overhead.
    The Windows Cache Extension for PHP includes a file cache that is used to store the content
    of the PHP script files in shared memory, which reduces the amount of file system operations
    performed by PHP engine.

  • Resolve File Path Cache — PHP scripts very often include or operate
    with files by using relative file paths. Every file path has to be normalized to
    an absolute file path by the PHP engine. When a PHP application uses many PHP files and
    accesses them by relative paths, the operation of resolving the paths may negatively
    impact the application’s performance. The Windows Cache Extension for PHP
    provides a Resolve File Path cache, which is used to store the mappings between relative
    and absolute file paths, thereby reducing the number of path resolutions that the
    PHP engine has to perform.

  • User Cache (available since version 1.1.0) — PHP scripts can take advantage of
    the shared memory cache by using the user cache API’s. PHP objects and variables can be stored in the
    user cache and then re-used on subsequent requests. This can be used to improve performance of PHP scripts
    and to share the data across multiple PHP processes.

  • Session Handler (available since version 1.1.0) — The WinCache session handler can be used to
    store the PHP session data in the shared memory cache. This avoids file system operations for reading
    and writing session data, which improves performance when large amount of data is stored in PHP session.

There are no user contributed notes for this page.

Leader badge

Windows Cache Extension for PHP is a PHP accelerator that is used to increase the speed of PHP applications running on Windows and Windows Server. The extension includes PHP opcode cache, user data cache, session cache, file system cache and relative path cache.

Features

  • PHP 5.2 through 5.6 and 7.0 through 7.2 support
  • Configurable file cache
  • Configurable PHP opcode cache (PHP 5.x only)
  • Relative file path cache
  • PHP functions to obtain information about the cache status

Automate and centralize VAT tax Icon

Vertex Indirect Tax O Series is a robust indirect tax calculation engine that integrates with ERPs, billing systems, or e-commerce platforms to deliver accurate tax determination on every sales and purchase transaction.

User Ratings


4.4

out of 5 stars

★★★★★

★★★★

★★★

★★

ease
1 of 5
2 of 5
3 of 5
4 of 5
5 of 5

0 / 5

features
1 of 5
2 of 5
3 of 5
4 of 5
5 of 5

0 / 5

design
1 of 5
2 of 5
3 of 5
4 of 5
5 of 5

0 / 5

support
1 of 5
2 of 5
3 of 5
4 of 5
5 of 5

0 / 5

User Reviews

  • All
  • ★★★★★
  • ★★★★
  • ★★★
  • ★★
  • it seems to not work on windows server 2019. i manually installed php 5.6 to work with iis and the wincache does not show up in the phpinfo. also the error log complains wincache is not loading..

  • I’ve detected considerable performance increase. Think about VPS with Windows instead Linux.

  • php5.5.0 nts x64 for wincache do not exists.

  • 1 user found this review helpful.

  • 什么时候发布支持PHP5.4的wincache,用起来感觉非常good,效果明显。

Read more reviews >

Additional Project Details

2009-12-15
ETW Tracing & Manifest file:
----------------------------

As of May 26, 2015, there is no mechanism to have the Win32 build environment
call the $(MC) command with the right parameters against the ETW Manifest file.
So, if you make changes to the ETW manifest file, you'll need to hand-execute
the $(MC) command with the right parameters, and check in the changed files.

Command to execute (in the pecl\wincache directory):
  mc -um -e h -h .\ -r .\ wincache_etw.man

Files generated by 'mc':
  wincache_etw.h
  wincache_etw.rc
  MSG00001.bin
  wincache_etwTEMP.BIN

To register the manifest, open an admin cmd window, and execute the following
command:
  wevtutil im wincache_etw.man

If you've previously registered a manifest, you'll have to unregister the
manifest, and then re-register it.
  wevtutil um wincache_etw.man
  wevtutil im wincache_etw.man

To capture ETW traces, you can create a log profile with logman:

  logman create trace wincache_etw -p "{F7AD0093-D5C3-46B9-BEEA-A9FCEC7E1408}" -o c:\temp\wincache_etw
  logman start wincache_etw
  <...do your repro...>
  logman stop wincache_etw
  tracerpt wincache_etw_000001.etl -import wincache_etw.man

You'll need to copy the wincache_etw.man to the machine where you're executing
wincache, and wherever you're running tracerpt.exe.


  

In this article you’ll learn how to install PHP on Windows Server IIS. With the Windows Cache Extension for PHP (WinCache). WinCache enabled PHP gives you great performance for WordPress, Drupal and Joomla websites, and decreases CPU usage. In this post I’ll show you it’s not hard to set up a high performing PHP stack on Windows Server (IIS). So, let’s optimize our PHP hosting on Windows Server!

Install PHP and WinCache on IIS

this is an older article that I’ve rewritten. Therefore not all version numbers are up to date and at the time of this writing (March 2020), a stable WinCache version for PHP 7.4 is not available. Where possible I’ll try to use the latest PHP 7.3 versions.

What is the Windows Cache Extension for PHP (WinCache)? WinCache is a great addition for your PHP configuration on Windows Server as it provides caching for high performance PHP application hosting in IIS ;-) Want to see the effect of Wincache on a site? See my post The WinCache effect: Save with object caching.

However, over the years, problems were reported with either the installation and configuration of the Windows Cache (WinCache), or even with buggy versions. Just search forums.iis.net for examples. And this is why I created this how to install and configure WinCache for PHP on IIS guide. Setting up PHP and WinCache is absolutely not that difficult. Where possible, I show you how to use the IIS Manager GUI and AppCmd and PowerShell commands.

You can also follow this guide if you want to install PHP in IIS without Wincache!

The Windows Cache Extension for PHP is a PHP accelerator that is used to significantly increase the speed of PHP applications running on the Windows operating system. Any PHP application can take advantage of the functionality provided by the Windows Cache Extension for PHP without any code modifications. All that is required is that the extension is enabled and loaded by the PHP engine.

http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/use-the-windows-cache-extension-for-php

Remember that the IIS FastCGI extension provides thread safety, therefore we use non thread safe (NTS) versions of our software.

Protip: Never try to set up a new configuration in a live environment! Always use a development-, testing- and staging PHP environment before deploying your PHP configuration to your live PHP hosting environment. This may go very bad when you haven’t tested your set-up.

Download and configure PHP and WinCache

Download PHP and WinCache in a few steps:

  1. make sure you have the latest Visual C++ Redistributable for Visual Studio 2015-2019 x64 / x86 installed.
  2. download VC15 x64 Non Thread Safe from http://windows.php.net/download/. Non Thread Safe because we’re using IIS/FastCGI.
  3. unzip the files to a location on the server, for instance d:\scripts\php73 and edit the php.ini accordingly.
  4. download WinCache 2.0.0.8 for PHP 7.3 from https://sourceforge.net/projects/wincache/files/wincache-2.0.0/, choose the right version: x86 or x64!
  5. run the executable wincachewpi-2.0.0.8-7.3-nts-vc15-x86.exe to unpack the files in, for instance c:\temp.
    1. if you happen to download the WPI variant, and don’t have a PHPPATH property set, use an administrative install with msiexec to extract the contents from the .msi file: msiexec /a c:\temp\wincache73x86wpi.msi /qb TARGETDIR=c:\temp\wincache73x86
  6. copy the file c:\temp\wincache73x86\PFiles\php_wincache.dll to the d:\scripts\php73\ext location.

WinCache versions
If you to try to set up a buggy version of WinCache, just try a different version, or perhaps even a development version to overcome errors. Test various newer or older version in your development environment, you can download these WinCache versions from http://sourceforge.net/projects/wincache/files/development/.

Configure PHP and WinCache settings

I always provide a dedicated php.ini file for Wincache enabled websites called php.wincache.ini. I recommend you do the same. You can configure PHP and WinCache in a few short steps (WinCache configuration below the list items):

  1. copy php.ini to php.wincache.ini and open php.wincache.ini in your favorite editor
  2. add extension=php_wincache to the Dynamic Extensions list
  3. manually create a [WinCache] configuration section and turn on the WinCache extension (see all configuration options: http://www.php.net/manual/en/wincache.configuration.php). Other WinCache-settings may be left at their default settings.
[WinCache]
; Enables or disables the file cache functionality. Defaults to 1
wincache.fcenabled = 1
; Enables or disables the user cache functionality. Defaults to 1
wincache.ucenabled = 1
  1. It is important look at the following php.ini settings, and change them to your needs
output_buffering = Off
display_errors = Off
log_errors = Off
cgi.force_redirect = 0
cgi.fix_pathinfo = 1
fastcgi.impersonate = 1
fastcgi.logging = 0

While you’re at it, tune PHP realpath_cache_size and OPcache too. WinCache’s opcode cache is deprecated in favor of Zend Opcache (php_opcache). On Windows Server, PHP OPcache gives a great performance boost too, if you’ve optimized its configuration properly.

Protip: Don’t turn off CURLOPT_SSL_VERIFYPEER to fix issues with SSL, fix your PHP configuration.

PHP is now configured to use WinCache, if we set the handler for it in IIS. We created a different PHP configuration file called php.wincache.ini, remember. That one needs to be activated as a PHP handler in IIS.

Disable WinCache
Suppose you want to disable WinCache completely. Open up your php.wincache.ini file and remove the php_wincache.dll extension by prepending the line with a semi-colon and thus commenting it out:

  • ; extension=php_wincache

Or you may just change back to your default IIS PHP handler and WinCache is disabled too.

How to set up a PHP handler using IIS Manager

Open up the FastCGI Settings feature of the web server in IIS Manager.

IIS Manager FastCGI Settings

In the Actions pane, click Add Application…

Set up PHP as a FastCGI application

  • Full Path: d:\scripts\php73\php-cgi.exe
  • Arguments: -c d:\scripts\php73\php.wincache.ini

You can tweak other settings, such as Instance MaxRequests and Max Instances later. After a while when the server is running smoothly. Don’t start over-optimizing your IIS web server configuration too soon.

Open up the EnvironmentVariables Collection and add two environment variables, which tells FastCGI where the .ini-file is located and sets the native PHP process-recycling.

IIS FastCGI Application properties – click the … to open up the EnvironmentVariables Collection window
EnvironmentVariables Collection Editor – Add PHPRC environment variable to FastCGI
Add PHP_FCGI_MAX_REQUESTS environment variable to FastCGI

Hint: by setting instanceMaxRequests to a value that is smaller than or equal to PHP_FCGI_MAX_REQUESTS, you can make sure that the native PHP process-recycling logic will never start. See “Configuring FastCGI to Host PHP Applications (IIS 7)“.

OPENSSL_CONF is your third environment variable, and equally important. It configures OpenSSL properly so you don’t have to turn off CURLOPT_SSL_VERIFYPEER in your scripts.

Seet OPENSSL_CONF environment variable to FastCGI

Now, open up the Handler Mappings feature in IIS Manager.

Handler Mappings icon in IIS Manager

Scroll down to *.php and click Edit... in the Actions pane (or just double click):

*.php handler in IIS

Fill out the requested information. The pipe (|) is important, the full Executable becomes d:\scripts\php73\php-cgi.exe|-c d:\scripts\php73\php.wincache.ini

Now click the Request Restrictions… button.

Set the handler Request Restrictions to invoke the handler only if request is mapped to File. If you forget this step, you may leave your webserver open to a nasty ASP.NET source code disclosure vulnerability and you may receive “No input file specified.” errors instead of a 404 Not Found page.

Request Restrictions

Click OK twice (in the Request Restrictions screen and Edit Module Mapping) to exit. In the next screen, you may click NO to not set up a FastCGI application, because we already manually did.

AppCmd to set up FastCgi and PHP configuration

In addition, command-line gurus may use AppCmd to configure FastCGI applications and PHP handlers. I’m not going to post all AppCmd commands here, they’re already in older posts like here and here.

Some AppCmd commands you might need when setting up PHP and FastCgi on the command-line:

Appcmd set config /section:system.webServer/fastCGI
 /+"[fullPath='d:\scripts\php73\php-cgi.exe', arguments='-c d:\scripts\php73\php.wincache.ini', 
 maxInstances='0', idleTimeout='300', activityTimeout='70', 
 requestTimeout='90', instanceMaxRequests='9999', 
 protocol='NamedPipe', flushNamedPipe='False']" /commit:apphost
AppCmd set config -section:system.webServer/fastCgi
 /+"[fullPath='d:\scripts\php73\php-cgi.exe', arguments='-c d:\scripts\php73\php.wincache.ini'].environmentVariables.
 [name='PHPRC',value='d:\scripts\php73\php.wincache.ini']" /commit:apphost
AppCmd set config -section:system.webServer/fastCgi
 /+"[fullPath='d:\scripts\php73\php-cgi.exe', arguments='-c d:\scripts\php73\php.wincache.ini'].environmentVariables.
 [name='PHP_FCGI_MAX_REQUESTS',value='10000']" /commit:apphost
AppCmd set config /section:system.webServer/handlers 
  "-+[name='PHP',
    path='*.php',
        verb='*',
        modules='FastCgiModule',
        scriptProcessor='d:\scripts\php73\php-cgi.exe|-c d:\scripts\php73\php.wincache.ini',
        resourceType='File',
        allowPathInfo='true',
        requireAccess='Script',
        responseBufferLimit='256']"

In PowerShell, escape the single quote ' with a backtick `. Or to put in your website’s web.config file (if you’re allowed to do so as user):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<system.webServer>
		<handlers>
			<remove name="PHP"/>
			<add name="PHP" path="*.php" verb="*" modules="FastCgiModule"
				scriptProcessor="d:\scripts\php73\php-cgi.exe|-c d:\scripts\php73\php.wincache.ini"
				resourceType="File"
				allowPathInfo="true"
				requireAccess="Script"
				responseBufferLimit="256"
			/>
		</handlers>
	</system.webServer>
</configuration>

Troubleshooting PHP configuration on IIS

Tip: use the command-line!

Sometimes things go wrong. It just does, for example when you make a typo. That is not a problem. You can very easily troubleshoot PHP configuration errors on the command line. Just run php-cgi.exe with some parameters and a pop-up will show an error (no error means everything is OK).

  1. load php.wincache.ini and run a .php-file (one line)
d:\scripts\php73\php-cgi.exe
  -c d:\scripts\php73\php.wincache.ini
  z:\sites\wwwroot\site1.com\index.php
  1. load a Zend extension like ioncube_loader and run a .php-file (one line)
d:\scripts\php73\php-cgi.exe
  -z d:\scripts\php73\ioncube_loader_win_7.3.dll
  z:\sites\wwwroot\site1.com\index.php
  1. combine both ioncube_loader and php.wincache.ini (one line)
d:\scripts\php73\php-cgi.exe 
  -c d:\scripts\php73\php.wincache.ini 
  -z d:\scripts\php73\ioncube_loader_win_7.3.dll
  z:\sites\wwwroot\site1.com\index.php

WinCache opcode cache with PHP

With the release of WinCache version 1.3.5 for PHP 5.5, the WinCache opcode cache (ocenabled) is deprecated and removed since 2.0.0. WinCache opcode cache is deprecated in favor of PHP’s native OPcache, the Zend OPcache extension is in the PHP core available, but WinCache is still very valuable as file cache, session- and user cache.

Conclusion running PHP with WinCache in IIS

In this post I showed you how easy it is to install PHP with WinCache on IIS. This creates a high performance web stack to host high volume PHP-based web sites. However, caution is called for: Enabling WinCache for all hosted websites (as default) may run a server out of memory easily, if settings are not optimized. This is because Windows IIS reserves the configured amount of memory per website, and you should monitor IIS memory usage.

Note: script engines on OS partition: it’s beyond the scope of this post to explain the dangers of having websites and/or script engines on the same partition as the Operating System!

If you develop PHP and MySQL based web sites, you can even use WinCache to cache MySQL query results. This is a turbo boost for your website because the website doesn’t have to create a connection to the back-end database for every request. The WinCache functions are easily ported to APC, and vice versa, and thus you are not stuck on one hosting platform.

Please be aware that the development of WinCache has been discontinued by Microsoft. If you want to, you can get involved in PHP development or fork the WinCache project on GitHub. Don’t expect PHP 8 support in WinCache unless you create it.

Here is some more PHP/WinCache development reading material for you:

  • https://www.php.net/get-involved
  • https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2
  • https://halfblood.pro/things-you-should-know-about-windows-cache-extension-for-php-93b7e013ea4c
  • https://social.msdn.microsoft.com/Forums/en-US/home?forum=iiswindowscachephp
  • https://sourceforge.net/projects/wincache/files/ (it is now less popular to host anything on SourceForge, but anyway you can find the latest installers (for PHP 7.3) under development folder)

  • Windows cmd out to file
  • Windows cmd удалить все файлы в папке
  • Windows c usb флешки без установки
  • Windows chip 2014 final скачать без торрента
  • Windows cmd list all services