WinCache, Apache and a pretty graph!
I really wanted to focus this post on WinCache, rather than OpCode Cachers in general – but it turned into a general post with a star contender. From the Windows Cache extension for PHP website as Microsoft.com:
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 documentation makes no mention of Apache, only IIS. I decided to give it a try, and to my amazement, WinCache worked in Apache on Windows. After that I decided to compare the performance of WinCache with the other available options for Windows+Apache.
I referenced the following sites who performed similar tests, but in IIS:
- PHP on Windows: The WinCache 1.0 Benchmark – ibuildings.com techPortal, Ivo Jansch
- WinCache – Preliminary tests look REALLY good. – Cal Evans
You can grab WinCache, and information about it, here:
- Windows Cache extension for PHP website on Microsoft.com
- The PECL repository page for WinCache
- Ruslan Yakushev’s blog posts about WinCache (WinCache Developer)
Testing Environment
- Hardware
- AMD Athlon 64 3800+ (2.50GHz, single core)
- 2.0GB DDR2
- Software
- Windows Server 2003 w/ SP2
- MySQL 5.1.40, locally installed
- Apache 2.2.14 vc9
- mod_fcgid 2.3.4
- php 5.3.1 ts/nts vc9
- WordPress 2.9.1 base install (wordpress is a good “everyman” product for simulating “real world” use, even if its code is ugly)
- OpCode Cachers
- APC 3.1.3.0 (3.1) (NTS)
- WinCache 1.0.1117.0 (1.0, stable) (NTS)
- XCache 2.0.0-dev(r688) (TS)
- eAccelerator 0.9.6rc1 (TS)
Test Method
To run an unbiased test, I tried to remove as many variables as possible. A batch script was written to perform the following (thus garaunteeing that every test was identical):
- Stop the apache service
- Start the apache service
- Run ab (Apache Bench), piping output to a text file
- Repeat 1-3 with incremented Concurrency levels (1, 3, 5, 10)
- Notify me that all tests have been completed.
Aside from testing the relative performance of each opcode cacher, I also wanted to see how well they performaned under differnt levels of “stress”, which is why I included Step 4 with different levels of concurrency. After each test-run, I would switch out the opcode cacher in PHP.ini, making sure that the individual opcode cacher settings were “equal” in all ways possible (same amount of shared memory, etc etc). After all test-runs were completed I went through the test files that were generated and compared the results in various graphs.
To form a baseline, I also ran the test with no opcode cacher, in both TS (PHP as a module) and NTS (PHP through FastCGI) setups.
Results
The results were extremley eye-opening for me. Here is the pretty graph:

Let’s disect this graph a little bit.
- Not using an OpCode cacher, if able to, is stupid. The performance gain from using ANY of the available OpCode cachers is amazing. For that matter, any form of caching; If you aren’t caching ANYTHING, you are stupid.
- Non-Thread Safe (NTS, FastCGI) PHP performs better than Thread Safe (TS, Module) PHP. Duh.
- WinCache works in Apache. This one is obvious from the graph & my tests, but if you were to go read documentation for WinCache it strictly talks about IIS. This is great news for Apache on Windows, because WinCache is made specifically for windows – unlike the other OpCode cachers which are usually made with Linux in mind and ported to Windows as an afterthought.
- XCache’s performance increased as the “stress” increased. All other opcode cachers either performed the same accross the board or decreased in performance as the “stress” level increased. It would be interesting to run larger concurrency tests to see where XCache’s performance falls off at.
- WinCache came out as the top performing opcode cacher, on this setup, in this environment, during these tests.
- XCache and APC performed exactly opposite of each other as the “stress” increased. eAccelerator was practically the “best fit line” for XCache and APC, but it did performed slightly better when averaged across concurrency levels.
- APC performed almost as well as WinCache at the lowest (none) concurrency level.
What does this all mean?
It means that in my tests, on Windows, in Apache, using bleeding edge software, I have shown that WinCache is a viable option for Windows development and production servers. I have not shown that WinCache is THE BEST option or the ONLY option; just that is an option — regardless of what my graphs show. Why? Because benchmarks suck and they only exist to show a relative level of performance as compared to others in an isolated environment. You may have different results. You may need additional features. You may have political/fanboi issues with using one or the other. Will I be using WinCache going forward? Yes, and I will also recommend it to others.
Interesting findings – the reason Wincache doesn't mention Apache is because MOST people use mod_php with apache, even on windows (php5apache2_2.dll ring a bell?) When using mod_php on windows you need to use the thread safe version of PHP – apache threaded, mod_php threaded, all happy.
Wincache does not DO thread safe – hence it can only be used with PHP fastcgi – so if you're using fastcgi with PHP on apache on windows (if you're deploying apache on windows I'd highly suggest it) then it works great
What I take away from this is a set of metrics that shows that *any* opcode cache technology consistently gives between 300-400% performance improvement over using no opcode caching.
This may seem like another “duh” point to you and other PHP-savvy people, but there are a lot of PHP developers out there (and not just newbies) who don’t know anything about opcode caching — they don’t know that it gives this large a benefit, and they don’t know it’s so transparent to employ in any application.
So, well done on the blog post! Keep spreading the word!
Exactly! That is the point I wanted to get across, regardless of my WinCache testing/findings, was that ANY form of caching is good, and opcode caching is very beneficial.
Hi,
I can not manage to install fastcgi on apache 2.2 server. Is there any installation guide about this? I have tried fastcig.com apache.org but none of them works for me.
Interesting benchmark.
The advantages of opcode caching (& other forms of content caching) are somewhat reduced if you use fastcgi with multiple backend PHP processes – these caching technologies work best with a single parent PHP process. Each PHP process (with eAcc/X/APC) will have it’s own separate cache memory. Hence, if you’re running 10 fastcgi processes – the memory cache is duplicate 10 times… which kind of defeats the whole purpose (apart from the huge memory hogging)
Besides, eAccelerator, xcache & even APC has some serious stability issues – try running Apache+eAcc+mod_php unattended for a few days – when (there is no if) eacc seg faults, it will bring down the whole server! That’s one of the reasons why most shared hosting companies don’t deploy opcode cachers. IMHO, APC shows slightly better stability than the others, but still it’s not there quite.
So it comes at a price – either you’ll have to settle for improved performance, or stability. Unfortunately, you can’t have both – not at the moment at least.
For wordpress, I think it’s safer to use wp-supercache.
to invar brass:
I too have heard all the stories about eAccelerator causing segfaults and apache to crash. I admin a few reasonable high traffic (>100k page views/mo) sites using Drupal 6 on Apache2, PHP5.2 (mod_php5), eAccelerator 0.9.5.3 on FreeBSD 7.1 on a very modest (512M RAM) VPS (that also hosts the database server). These have been running with an uptime of over 1 year, without a single apache crash. Performance is excellent, and I have not experienced ANY issues related to op-code caching or apache. Do you have direct experience with these issues, or are you just repeating other somewhat outdated net references to eAccelerator issues?
@ Invar Brass
WinCache creates one cache for each IIS application pool which is then shared among all php processes serving that application pool. So cache is not duplicated in all the php processes. Also we have many customers running wincache on their servers without any problem (no crashes for months now).
useful! tired of eaccelerator on windows segfaulting
thanks for your nice article.
i have decided to use the nts php as fastcgi + wincache for my project;
Hi
I am using apc and joomla and get quite good stability. When i saw your benchmark I was very amazed and was trying to install wincache but get errors on missing dll… Do you have some directives on php package and dll too activate ?
Regards,
James
hi,
How to use wincache on Apache? Can you give us detailed instructions?
There is an all-in-one server package named XAMPP for Windows (http://www.apachefriends.org), which includes Apache inside. I want to use wincache on XAMPP, but I don’t know how.
Thanks.