File Change Notification support on WinCache 1.1 Beta2

As you all know we did a Beta2 release of WINCACHE 1.1 today. This is a very important release with lots of bug fixes and new features. I would encourage all current users of WINCACHE to upgrade to latest Beta2 build.

With this release we have File Change Notification implemented and this is my favorite feature irrespective of the fact that it hardly adds anything in terms of performance. When I started working on WINCACHE in it’s inception phase, this is how I used to test it:

  • Open a new file in Notepad++
  • Name it ‘bug.php’
  • Keep writing different PHP code and save
  • Run it in the browser to see if it is working fine

The process was okay to do exploratory testing but sometime the file edit will not show up in the browser because of the fact that we used to poll for file changes every 30 seconds by default. I would rather recycle my application pool or set wincache.chkinterval to a low value to get around this irritation.

Well this feature made my life absolutely rocking. No need to set low interval or recycle application pool. As soon as file is changed PHP process is notified of it and the cache is invalidated and new edited data is stored in the cache. What a relief? This annoyance was not only faced by me but also by lots of our users who complained about it in the forums and also in the form of bug at PHP bug database.

This makes a big difference in real life application. Let’s take the example of Joomla. One can go to administrator panel and change settings like set WINCACHE for user cache or session cache. Similar things can be done in other applications like SugarCRM. The problem was that without file change notification though the changes were done but the page still used to show old stale value. Reason, stale PHP file is already present in the WINCACHE shared memory and didn’t get refreshed with new edited settings. Now with Beta2 the changes will be seen instantaneously. Isn’t that cool?

One thing to be noted here is that file change notification will work on file system which supports it. Example, if your web site content is on a UNC share, it will not work and the code will automatically switch back to polling. You don’t need to do anything.

Now let’s see how we have implemented it. The majority of implementation is in file named wincache_notify.c and the corresponding header file. Look at function register_directory_changes which registers the directory which WINCACHE listen to. We are using the function ReadDirectoryChangesW to listen to change notification. We listen to following file change notification:


The beauty is that not all PHP process listens to a specific folder. Instead when a request comes that particular PHP process sees if the folder where the requested file lives is being listened by some PHP process or not. If not it registers itself to listen to that folder otherwise it just passes by. Also when a PHP process is getting recycled and if the process is listening to some folder the ownership is taken by another PHP process which is alive. This is done when a request comes and WINCACHE sees that folder is being listened but that particular PHP process no longer exists, the PHP process serving the request takes ownership of that folder.

File change notification also has got a scavenger which actually periodically removes the folder being listened if that folder reference count becomes zero. Now this is a very high level description of the implementation but should give you a fair idea about what’s going on.

I am also proud of this feature because this is a differentiating feature of WINCACHE with respect to all other caching solution which exists today. Special thanks to our developer Kanwal who implemented this. I will also talk about how I tested this feature but that’s another story.

So install the latest beta bits and send in your feedback. We would love to hear back from you.

Thanks for patient reading and good bye.


No Comments