After WinCache 1.0 release, two most requested features were user cache and session cache. We added both of these features in WinCache 1.1 beta1. We are very happy with the rate of adoption of user cache by PHP application developers. Many application developers have already added support for WinCache user cache in their applications and many are in the process of adding it. Earlier we were planning to add only these two features in WinCache 1.1 and then do more performance optimizations in WinCache 1.2 but later we decided to add these additional optimizations in 1.1 release itself. Because of this, we did beta2 release which has file change notification and function hooks support along with some small feature additions. Below is the full list of features which got added to WinCache 1.1 up to beta2 release.
1. User cache APIs – We have added APIs like wincache_ucache_get, wincache_ucache_set etc. (see full list here) which can be used to store and retrieve application data from the cache. Since the cache is shared among all PHP processes under an application pool, application developers can calculate data once, store it in the cache and then retrieve it in next request instead of calculating it every time. Database query results, site counters etc. are good candidates to be stored in user cache. These APIs behave much like user cache APIs available in APC to make it easier for developers to use existing code written for APC.
2. WinCache session handler – PHP provides three session handlers (files, shm, user) out of the box of which shared memory (shm) handler doesn’t work on windows. Session handler “files” is the most commonly used session handler on windows which is slow as it requires file read on every request. We have implemented a session handler in WinCache which keeps session data in shared memory which is much faster compared to files. Since session data is expected to survive PHP and IIS process recycles, data is persisted on disk by WinCache in the folder specified by session.save_path. Since session.save_path is not a system level configuration, WinCache creates a separate session cache for different values of session.save_path. WinCache 1.1 stored this data in memory allocated for user cache but WinCache beta2 allocates separate memory for session cache.
3. File change notification – WinCache now registers for change notifications to all folders under which a file is requested by file cache or opcode cache. When a file change notification is received, that file is removed from all the caches immediately. Doing this without incurring performance penalty required us to make all processes not listen to all the folders. So we designed a distributed change notification infrastructure which works without any master. Of all PHP processes running on the system for an application pool, only one of them listens to one folder. Other processes detects that a listener is present for the folder and do nothing. If a process dies, another process detects this situation and registers for a change listener itself. We made sure that no change is ever missed by this system and this system can easily scale to 100s of folders.
4. Function hooks – With file cache and file change notification infrastructure in place, we decided to rewrite some PHP APIs like file_get_contents, is_file etc on top of this infrastructure to make them faster. For this we have added ability to define function hooks in WinCache. WinCache 1.1 beta2 include this infrastructure but doesn’t include any function hooks. I am in the process of rewriting some functions and we will enable these hooks in WinCache 1.1 RC release.
5. In WinCache 1.0, we create separate cache for PHP processes running under one process. This didn’t work too well in web garden scenarios. WinCache 1.1 has solved this problem by sharing cache for all PHP processes running under worker processes belonging to one application pool. If application pool id is not available (as in Apache), it will switch to old behavior.
6. Added optional boolean argument summaryonly to all WinCache info functions. Ruslan requested this feature so that wincache_ocache_fileinfo function calls made by his wordpress widget on his site (http://ruslany.net) are faster. And based on customer feedback we changed wincache_ucache_info to accept an optional key to make it return information on just one user cache entry and exposed user cache entry size in each entry.
7. Drupal application developers requested us to add wincache_lock, wincache_unlock APIs and we have added these in 1.1 Beta2 release. By default lock created by wincache_lock is scoped to all PHP processes sharing the cache. If you want a global lock, set optional argument isglobal to true.
8. WinCache statistics page (wincache.php) has been changed to show user cache and session cache data and fixed bugs reported by customers on http://pecl.php.net/bugs/.
We are planning to add replacement APIs for PHP functions which deal with files in WinCache 1.1 RC release. We will also enable function hooks so that calls to PHP file APIs gets re-routed to these APIs. And as always, we will implement feature requests and fix bugs reported by you.