• 首页
  • css3教程
  • html5教程
  • jQuery手册
  • php7教程
  • MySQL手册
  • apache手册
  • 位置: php7教程 -> PECL扩展库

    wincache(缓存)

    The extension is currently supported only on the following configurations:

    Windows OS:

    • Windows XP SP3 with IIS 5.1 and » FastCGI Extension
    • Windows Server 2003 with IIS 6.0 and » FastCGI Extension
    • Windows Vista SP1 with IIS 7.0 and FastCGI Module
    • Windows Server 2008 with IIS 7.0 and FastCGI Module
    • Windows 7 with IIS 7.5 and FastCGI Module
    • Windows Server 2008 R2 with IIS 7.5 and FastCGI Module

    PHP:

    • PHP 5.2.X, Non-thread-safe build
    • PHP 5.3 X86, Non-thread-safe VC9 build

    Note: The WinCache Extension can only be used when IIS is configured to run PHP via FastCGI.

    安装

    此 » PECL 扩展未与PHP 捆绑。

    安装此 PECL 扩展相关的信息可在手册中标题为PECL扩展的安装章节中找到。更多信息如新的发行版本、下载、源文件、维护人员信息及变更日志等,都在此处: » https://pecl.php.net/package/wincache.

    There are two packages for this extension: one package is for PHP versions 5.2.X, and the other package is for PHP 5.3.X. Select the package that is appropriate for the PHP version being used.

    To install and enable the extension, follow these steps:

    1. Unpack the package into some temporary location.

    2. Copy thephp_wincache.dllfile into the PHP extensions folder. Typically this folder is called "ext" and it is located in the same folder with all PHP binary files. For example:C:\Program Files\PHP\ext.

    3. Using a text editor, open the php.ini file, which is usually located in the same folder where all PHP binary files are. For example:C:\Program Files\PHP\php.ini.

    4. Add the following line at the end of the php.ini file:extension = php_wincache.dll.

    5. Save and close thephp.inifile.

    6. Recycle the IIS Application Pools for PHP to pick up the configuration changes. To check that the extension has been enabled, create a file calledphpinfo.phpwith a PHP code that calls phpinfo function.

    7. Save thephpinfo.phpfile in the root folder of a IIS web site that uses PHP, then open a browser and make a request to http://localhost/phpinfo.php. Search within the returned web page for a section calledwincache. If the extension is enabled, then the phpinfo output will list the configuration settings provided by the WinCache.

    Note: Do not forget to removephpinfo.phpfile from the web site's root folder after verifying that extension has been enabled.

    If you're looking for the DLLs for WinCache 2.0.0 (for use with PHP7+), here's a quick outline of the steps I took:
    - Download the appropriate build from wincache's repository on sourceforge
    - Run the .exe and extract the archive to a temporary directory
    - Using 7zip, unpack the .msi within that temporary directory
    - Add the .dll extension to the file named "php_wincache"
    If you're after pre-compiled binaries for WinCache, you can find them here: http://www.iis.net/download/WinCacheForPhp on the right-hand side of the page (under the Web Platform Installer button)
    The wincache version for 7.0 is compiled for php7.dll not the thread safe php7ts.dll. You may need to compile the source for wincache or change to the non thread safe version.

    运行时配置

    这些函数的行为受php.ini中的设置影响。

    The following table lists and explains the configuration settings provided by the WinCache extension:

    WinCache configuration options
    名字默认MinimumMaximum可修改范围更新日志
    wincache.fcenabled"1""0""1"PHP_INI_ALLAvailable as of WinCache 1.0.0
    wincache.fcenabledfilter"NULL""NULL""NULL"PHP_INI_SYSTEMAvailable as of WinCache 1.0.0
    wincache.fcachesize"24""5""255"PHP_INI_SYSTEMAvailable as of WinCache 1.0.0
    wincache.fcndetect"1""0""1"PHP_INI_SYSTEMAvailable as of WinCache 1.1.0
    wincache.maxfilesize"256""10""2048"PHP_INI_SYSTEMAvailable as of WinCache 1.0.0
    wincache.ocenabled"1""0""1"PHP_INI_ALLAvailable as of WinCache 1.0.0. Removed as of 2.0.0.0
    wincache.ocenabledfilter"NULL""NULL""NULL"PHP_INI_SYSTEMAvailable as of WinCache 1.0.0. Removed as of 2.0.0.0
    wincache.ocachesize"96""15""255"PHP_INI_SYSTEMAvailable as of WinCache 1.0.0. Removed as of 2.0.0.0
    wincache.filecount"4096""1024""16384"PHP_INI_SYSTEMAvailable as of WinCache 1.0.0
    wincache.chkinterval"30""0""300"PHP_INI_SYSTEMAvailable as of WinCache 1.0.0
    wincache.ttlmax"1200""0""7200"PHP_INI_SYSTEMAvailable as of WinCache 1.0.0
    wincache.enablecli001PHP_INI_SYSTEMAvailable as of WinCache 1.0.0
    wincache.ignorelistNULLNULLNULLPHP_INI_ALLAvailable as of WinCache 1.0.0
    wincache.namesaltNULLNULLNULLPHP_INI_SYSTEMAvailable as of WinCache 1.0.0
    wincache.ucenabled101PHP_INI_SYSTEMAvailable as of WinCache 1.1.0
    wincache.ucachesize8585PHP_INI_SYSTEMAvailable as of WinCache 1.1.0
    wincache.scachesize8585PHP_INI_SYSTEMAvailable as of WinCache 1.1.0
    wincache.rerouteiniNULLNULLNULLPHP_INI_SYSTEMAvailable as of WinCache 1.2.0. Removed as of 1.3.7
    wincache.reroute_enabled101PHP_INI_SYSTEM | PHP_INI_PERDIRAvailable as of WinCache 1.3.7
    wincache.srwlocks101PHP_INI_SYSTEMAvailable as of WinCache 1.3.6.3. Removed as of 2.0.0.0
    wincache.filemapdirNULLNULLNULLPHP_INI_SYSTEMAvailable as of WinCache 1.3.7.4

    WinCache Statistics Script

    The installation package for WinCache includes a PHP script,wincache.php, that can be used to obtain cache information and statistics.

    If the WinCache extension was installed via the Microsoft Web Platform Installer, then this script is located in%SystemDrive%\Program Files\IIS\Windows Cache for PHP\. On a 64-bit version of the Windows Server operating system, the script is located in%SystemDrive%\Program Files (x86)\IIS\Windows Cache for PHP. If the extension was installed manually, then thewincache.phpwill be located in the same folder from which the content of the installation package was extracted.

    To usewincache.php, copy it into a root folder of a Web site or into any subfolder. To protect the script, open it in any text editor and replace the values forUSERNAMEandPASSWORDconstants. If any other IIS authentication is enabled on the server, then follow the instructions in the comments:

    Example #1 Authentication configuration forwincache.php

    <?php
    /**
     * ======================== CONFIGURATION SETTINGS ==============================
     * If you do not want to use authentication for this page, set USE_AUTHENTICATION to 0.
     * If you use authentication then replace the default password.
     */
    define('USE_AUTHENTICATION', 1);
    define('USERNAME', 'wincache');
    define('PASSWORD', 'wincache');
    /**
     * The Basic PHP authentication will work only when IIS is configured to support 
     * Anonymous Authentication' and nothing else. If IIS is configured to support/use
     * any other kind of authentication like Basic/Negotiate/Digest etc, this will not work.
     * In that case use the array below to define the names of users in your 
     * domain/network/workgroup which you want to grant access to.
     */
    $user_allowed = array('DOMAIN\user1', 'DOMAIN\user2', 'DOMAIN\user3');
    /**
     * If the array contains string 'all', then all the users authenticated by IIS
     * will have access to the page. Uncomment the below line and comment above line
     * to grant access to all users who gets authenticated by IIS.
     */
    /* $user_allowed = array('all'); */
    /** ===================== END OF CONFIGURATION SETTINGS ========================== */
    ?>
    

    Note: Always protect thewincache.phpscript by using either the built-in authentication or the server's authentication mechanism. Leaving this script unprotected may compromise the security of your web application and web server.

    WinCache Session Handler

    The WinCache session handler (available since WinCache 1.1.0) can be used to configure PHP to store the session data in shared memory session cache. Using shared memory instead of the default file session storage helps improve performance of PHP applications that store large amount of data in session objects. Wincache session cache uses file-backed shared memory, which ensures that the session data is not lost during recycling of IIS application pools.

    To configure PHP to use WinCache session handler set thephp.inisetting session.save_handler towincache. By default the Windows temporary file location is used for storing the session data. To change the location of the session file use session.save_path directive.

    Example #1 Enabling WinCache session handler

    session.save_handler = wincache
    session.save_path = C:\inetpub\temp\session\
    Just as an fyi to anyone who has similar issues. WinCache v1.1.x would not write sessions to files under certain conditions. This means that all sessions are lost whenever an app-pool recycle occur. Here is the work around:
    If your app-pool name has periods (.) in it, change them to underscores (_). So an app-pool named www.somesite.com should be renamed to www_somesite_com.
    You can see the discussion here:
    http://forums.iis.net/p/1171996/1957839.aspx#1957839
    IF you use Apache and Session not work add to FCGID
    DefaultInitEnv APP_POOL_ID "DefaultAppPool"

    WinCache Functions Reroutes

    NOTE:wincache.rerouteini was removed as of WinCache 1.3.7.0. It has been replaced with automatic function reroutes. See: wincache.reroute_enabled.

    The WinCache functions reroutes (available since WinCache 1.2.0, removed since WinCache 1.3.7.0) can be used to replace built-in PHP functions with their equivalents that are optimized for a particular purpose. WinCache extension includes Windows-optimized implementation of PHP file functions that may improve performance of PHP applications in cases when PHP has to access files on network shares. The optimized implementation is provided for the following functions:

    • file_exists
    • file_get_contents
    • readfile
    • is_readable
    • is_writable
    • is_dir
    • realpath
    • filesize

    To configure WinCache to use the functions reroutes use the filereroute.inithat is included in WinCache installation package. Copy this file into the same directory wherephp.inifile is located. After that add the wincache.rerouteini setting inphp.iniand specify an absolute or relative path to thereroute.inifile.

    Example #1 Enabling WinCache functions reroutes

    wincache.rerouteini = C:\PHP\reroute.ini

    Note: If WinCache functions reroutes are enabled it is recommended to increase the WinCache file cache size. This can be done by using wincache.fcachesize setting.

    Thereroute.inifile contains the mappings between the native PHP functions and their equivalents in WinCache. Each line in the file defines a mapping by using the following syntax:

    <PHP function name>:[<number of function parameters>]=<wincache function name>

    The example of the file is shown below. In this example the calls to PHP function file_get_contents() will be replaced with calls to wincache_file_get_contents() only if the number of parameters passed to the function is less than or equals to 2. Specifying the number of parameters is useful when replacement function does not handle all the function's parameters.

    Example #2 Reroute.ini file content

    [FunctionRerouteList]
    file_exists=wincache_file_exists
    file_get_contents:2=wincache_file_get_contents
    readfile:2=wincache_readfile
    is_readable=wincache_is_readable
    is_writable=wincache_is_writable
    is_writeable=wincache_is_writable
    is_file=wincache_is_file
    is_dir=wincache_is_dir
    realpath=wincache_realpath
    filesize=wincache_filesize
    Prior to Wincache 1.3.7.0 rerouting was broken, see this in the official forums:
     http://forums.iis.net/t/1213205.aspx?Function+reroute+not+working]
     
    After that version, file rerouting functions are enabled by default, to disable them use:
     
     wincache.reroute_enabled=0