# Windows Cache for PHP

# Introduction

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.

- Installing/Configuring
  - Requirements
  - Installation
  - Runtime Configuration
  - WinCache Statistics Script
  - WinCache Session Handler
  - WinCache Functions Reroutes
- WinCache Functions
  - wincache_fcache_fileinfo — Retrieves information about files cached in the file cache
  - wincache_fcache_meminfo — Retrieves information about file cache memory usage
  - wincache_lock — Acquires an exclusive lock on a given key
  - wincache_ocache_fileinfo — Retrieves information about files cached in the opcode cache
  - wincache_ocache_meminfo — Retrieves information about opcode cache memory usage
  - wincache_refresh_if_changed — Refreshes the cache entries for the cached files
  - wincache_rplist_fileinfo — Retrieves information about resolve file path cache
  - wincache_rplist_meminfo — Retrieves information about memory usage by the resolve file path cache
  - wincache_scache_info — Retrieves information about files cached in the session cache
  - wincache_scache_meminfo — Retrieves information about session cache memory usage
  - wincache_ucache_add — Adds a variable in user cache only if variable does not already exist in the cache
  - wincache_ucache_cas — Compares the variable with old value and assigns new value to it
  - wincache_ucache_clear — Deletes entire content of the user cache
  - wincache_ucache_dec — Decrements the value associated with the key
  - wincache_ucache_delete — Deletes variables from the user cache
  - wincache_ucache_exists — Checks if a variable exists in the user cache
  - wincache_ucache_get — Gets a variable stored in the user cache
  - wincache_ucache_inc — Increments the value associated with the key
  - wincache_ucache_info — Retrieves information about data stored in the user cache
  - wincache_ucache_meminfo — Retrieves information about user cache memory usage
  - wincache_ucache_set — Adds a variable in user cache and overwrites a variable if it already exists in the cache
  - wincache_unlock — Releases an exclusive lock on a given key
- Building for Windows
  - Prerequisites
  - Compiling and building
  - Verifying the build

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open