PHP Caching and Acceleration with XCache

December 20, 2006 by · 53 Comments 

Anyone who runs a dedicated server for web hosting will tell you that a great way to decrease the load on your server and decrease the page load time is to use a PHP Cache such as APC or eAccelerator. While the largest noticeable improvements are for those site that receive a lot of traffic or are under heavy load, any site, large or small can see benefit from a PHP cache. That said, in addition to the two caches mentioned above, a new player has recently entered the market: XCache.

I first started using APC about 2 years ago when the load on one of my servers was high enough that it was affecting load times and was costing me user traffic. I chose APC over eAccelerator because it was a bit easier to install (at the time) and because APC had a reputation for being a bit faster than eAccelerator. Shortly there after I noticed my httpd processes segfaulting and a bit of research also showed that APC had a bit of a record for instability under heavy load. With that in mind, I took the slight performance hit and installed eAccelerator (which is still way faster than using nothing at all).

Up until today, I was still using eAccelerator on all of my servers. However, a post on the forums prompted me to give XCache, the new PHP accelerator from the maker of lighttpd, a try. I've got to say, while I've only been using it for about 6 hours at this point, it blows eAccelerator out of the water, especially once you enable multiple caches (which benefits SMP systems).

If you're interested in some benchmarks of XCache, eAccelerator, APC, etc. then checkout the Five Opcode Cache Comparison on PHP on Fire.

The install is relatively simple, even from source, but the included config file doesn't actually do anything unless you make changes. As such, I've decided to put together a simple src.rpm for easily building XCache for your PHP server. I've tested the src.rpm with my PHP 5.1.6 and 5.2.0 tutorials, as well as the stock 4.3.9 install for CentOS 4.

The src.rpm will build an RPM package that includes the Cacher module. A default cache size of 32MB will be used and the number of caches will automatically be set to the number of processors on the build system (which is why I'm providing a src.rpm instead of an rpm). In addition, I've set the management console to be copied to "/var/www/html" in a folder called "xcache" (you will, however, have to set a password in on your own). In any case, the link to the source package is below, let me know how it works out if you try it.

Update (2/23/2007): The src.rpm below has been updated to take advantage of the patch at

Update (7/3/2007): The src.rpm below has been updated to use the 1.2.1 sources.

Update (9/24/2009): Package deleted, use the yum repository instead.

Digg this story


53 Responses to “PHP Caching and Acceleration with XCache”
  1. iDaemon says:

    I have a question. how can we make a continue reading link at first page blog like this one.

    please advise me.

  2. iDaemon says:

    I've done it Thanks

  3. Jason says:

    The article and src.rpm have been updated. I removed the version check from the spec file and now it builds just fine under PHP 4. I've tested 4.3.9 but assume that it would also work with 4.4.4 or any other reasonably new version of PHP.

  4. Nick says:

    Good review, I'm currently looking into installing a PHP cacher on my CentOS 3.8 box.

    I've got Apache 1.3.37 with PHP 5.2 installed. I tried installing APC but I keep getting an error like this:

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/ undefined symbol: OnUpdateBool in Unknown on line 0

    I've rebuilt Apache (via cPanel) but still can't get it working... I think I read somewhere to try turning off "Versioning" in the PHP config, so I might try that later...

    However I was thinking of giving Lighttpd and XCache a go, do you think it would be very difficult to install them given my current setup?

    Thanks in advance for any help.

  5. Jason says:

    It's been a very long time since I've worked with httpd 1.3.x but I doubt that it could cause a problem like this (given that APC & XCache are both PHP extensions, not httpd modules).

    Have you tried a different version of APC? Have you tried this src.rpm for XCache (and sticking with httpd)?

    As to lighttpd, I use it for many of my sites to serve static images from a second IP. I've even got one "high-traffic" site (about 1000 hits per second for an hour a month) that uses it exclusively. That said, if you're invested in a complex configuration in httpd, particularly one that uses .htaccess files, you may be better off going with litespeed over lighttpd as litespeed can read and understand httpd config files.

  6. Nick says:

    Thanks for the reply Jason, to be honest I haven't heard of litespeed so I'll look into it.

    I haven't tried a different version of APC, however removing the Versioning from the PHP config seemed to "work"... which means that I didn't give any PHP Warnings or errors, but if I visit the same web page twice, the second time an empty page is spat out, which seems to me like APC is possibly caching an empty page for some reason.

    So I think it's time to give XCache a go. Wish me luck! 🙂

  7. Tom says:

    You seem to be the authority on xcache so far, so I'd like to ask you a question about my xcache install that I cannot seem to resolve using the site's documentation. I installed from source and specified my own directories (trying to retain a particular structure) using the configure script. I did --enable-xcache and --enable-optimizer. When all was said and done and I had appended to my php.ini (which resides /etc/php/php.ini) the default xcache.ini settings, I went in there to change things to suit my needs. I increased the cache size to 32M, and directed zend_extension to the proper .so (/usr/lib64/extensions/no-debug-non-zts-20060613/ Afterward, I restarted my httpd (lighttpd) and saw the xcache banner when I php -v. However, viewing phpinfo(), nothing is displayed regarding xcache and when I try to use the admin, it tells me xcache is not loaded and it questions the existence of my php.ini. I checked the config settings for the admin both in php.ini and the admin config.php, and didn't see anything awry. Any ideas? Any input greatly appreciated.

  8. Jason says:

    Are you sure that that is the correct php.ini file? It sounds to me like you may have separate configs for the CLI version and the FastCGI version. Where does your phpinfo() page say that your config is located?

    If it's the same file, you'll need to find out where errors for PHP are logged. With Apache's httpd they are passed through to the httpd error_log. That may be the same for lighttpd with FastCGI and it may not be. In any case, finding that log (or creating it if logging is disabled) may help you determine why the module isn't being loaded.

  9. Tom says:

    Ah-ha. You were correct about the php.ini. That's strange though, I installed php from source and configured a custom location for php.ini, or at least I thought I did. Anyway, things seem to be working now. Thanks.

  10. Sezai says:

    Do you offer any professional installation service for xcache
    We have cpanel and redhat ent 4.0
    Or is there anyway you can publish a step by step instalaltion fro cpanel server owners?
    thank you

  11. Jason says:

    While I do provide professional services, I refuse to provide any support on CPanel servers. While it isn't your fault, CPanel is possibly the worst thing to ever happen to remote hosting. Why anyone would design a software package that compiles a major application (like PHP) from source on an RPM-based distro is beyond me.

    That said, if you want to install from source then you should see the article at the link below.

  12. rainlee says:

    Wed Mar 7 15:30:27 CST 2007 Info:lighttpd new arch fastcgi server is warming up,please Wait ...
    PHP Warning: PHP Startup: Unable to load dynamic library './no-debug-non-zts-20060613/' - ./no-debug-non-zts-20060613/ cannot open shared object file: No such file or directory in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library './no-debug-non-zts-20060613/' - ./no-debug-non-zts-20060613/ cannot open shared object file: No such file or directory in Unknown on line 0

  13. Jason says:

    Why are you trying to use multiple PHP caches? If you're going to use XCache then you need to remove (or at least comment out) APC.

  14. Shawn says:

    I do wish people would stop using Zend or IonCube as an excuse for laziness or 'code theft'; I really despise having various modules and loaders required that do virtually nothing but wrap around the pseudo-op encoded PHP.

    I'd love to give XCode a try on my dev boxes, but even everything I have there requires Zend Optimizer.

    Somebody shoot me.

    Thanks for the links to updating from the ancient Apache 2.0.x series, Jason. I'm a Freebsd guy in a Debian and CentOS world, and they're both beginning to taste absolutely awful.

  15. haxx says:

    can this be used on a vps? will it make any difference or just crash it?

  16. Jason says:

    Aside from resource limits and a kernel you inherit from VE0, there is next-to-no difference between a VPS an a full dedicated server. In fact, many of my sites are run from VPS accounts that I've created on my own dedicated servers using OpenVZ so that I can better control what level of resource access a site is allowed to have.

    As to your question, you should not have any problems running XCache on a VPS. The only things I can think of that might cause problems are if you are are a low-end account where you are only allocated 64 or 128MB of RAM or if the server you are on has been connsiderably oversold (at which point your use of extra RAM may cause the machine to swap to disk). In those cases, allocating memory to a PHP cache may actually hurt your performance.

    Regardless, you're not going to know if there is any benefit until you try it out. Just a final note though, if your site is not very busy, you're probably not going to be able to tell the difference. PHP Caches really only make a noticeable difference on busy servers.

  17. haxx says:

    wow, thanks for the quick reply. I really appreciate you taking away from your time to help others. I think I'll give it a try because my site is rather busy and relies heavily on php. Do you know if xcache has known issues conflicts with other software/server configs? And if it messes things up, can i easily remove/uninstall it?


  18. Jason says:

    If you build and install from the src.rpm I posted then removing it is as simple as typing "rpm -e php-xcache" and then restarting httpd. If you install from source then you'll need to remove the extension from wherever it was installed and make sure that the lines to load the extension have been removed from your php.ini file.

    As to what it won't work with, any other PHP caches should be removed or disabled and if you're using the Zend Optimizer you'll need to remove it (the Ioncube loaders work though). Other than that, I haven't heard of any problems.

  19. LPH says:


    You are writing in a language that does not translate. Is it possible for you to actually write out the steps? For example.

    Step One. Download RPM
    Step Two. rpm -Uvh
    Step Three. ????

    After step two, you do not explain what to do. In fact, the files to into


    Now what?

    The XCache website is full of the same cryptic jibberish and points to your site. Even your compile from source post is filled with assumptions about someone else's knowledge. I'm not trying to rag on you but wonder if you realize I would rather not install the product than spend all day trying to translate what you are trying to have me do on the server. Just simply write step one, two, three, etc and cut out the technobabble (smile).

  20. Jason says:


    The files and articles I post here are intended for an audience that knows how to compile a src.rpm package. If that doesn't include you then you should consider adding my yum repository to your system so that you can download binary packages, googling for "build src.rpm" (or something to that effect), or contacting me privately for a paid consulting job.

  21. Eric says:

    Hi Jason, thanks for the tutorial 🙂

    I had a few questions, though.

    I'm running CentOS 4.4.x, Apache/2.2.4, PHP 5.2.3 w/Zend Optimizer 3.2.8

    I know that ACP is incompatible with Zend Optimizer, but what about XCache? Will it work under the above setup? I'm rather new to all this "server stuff" after moving to my own server after years of being with shared hosts.

  22. Jason says:

    XCache 1.2.1 has improved support for the Zend Optimizer but don't take that as a guarantee. You're really better off ditching Zend if you can (most script providers also offer an IonCube version and that WILL work with XCache).

  23. linuxamp says:

    Rebuilt on CentOS 5 PHP 5.1.6 in 4 easy steps.

    rpm -qp --requires php-xcache-1.2.0_0.3.src.rpm
    yum install php-devel autoconf automake libtool
    rpmbuild --rebuild php-xcache-1.2.0_0.3.src.rpm
    rpm -ivh /usr/src/redhat/RPMS/i386/php-xcache-5.1.6_1.2.0-0.3.i386.rpm

    Vast improvement in page load time. Thanks!

  24. Jason says:


    I would suggest that you upgrade to the newest version (1.2.1) using the src.rpm I provide at the link below.

  25. linuxamp says:

    Thanks Jason, I saw that after I built this version. New version also works great.

  26. Corman says:

    When I usew the "" command I get the following output:

    "error: cannot create %sourcedir /usr/src/redhat/SOURCES"

    This is my server configuration:
    GenuineIntel, Intel(R) Pentium(R) 4 CPU 2.80GHz
    2048MB RAM
    100GB SATA non-raid
    Linux 2.6.9-42.EL (CentOS)
    Apache: 2.0.52-28.ent.centos4
    PHP: 4.3.9-3.22.4
    MySQL: 4.1.20-2.RHEL4.1

    PLESK 8.2!

  27. linuxamp says:

    Corman, I think you might not have permissions. Try su - or sudo. Also, as Jason stated earlier, there's a new version you should be using.

  28. Jason says:


    As mentioned, it sounds like you are running as a non-root user. If you are, you'll either need to change to root (bad), change the permissions on /usr/src/redhat (less bad but still bad if you're in a multi-user environment), or follow the directions at the link below.

  29. dean says:

    when trying to log into the xcache web i get the following error and am not being asked for a username or password? am i being thick. xcache works great though!!

    Fatal error: xcache_count(): unexpect 4 bytes of xcache.admin.pass, expected 32 bytes, the password after md5() in /var/www/html/xcache/xcache.php on line 103

    this is my xcache.ini,
    xcache.admin.auth = On
    xcache.admin.user = "test"
    ; xcache.admin.pass = md5($your_password)
    xcache.admin.pass = "test"

  30. Jason says:


    As the comment in the config file says, xcache.admin.pass needs to be 32 bytes, not 4. You need to generate the MD5 hash of your password and paste it into that field. If you're looking for an online MD5 calculator, I like the one below.

  31. dean says:

    In the words of the Great Homer Simpson "DOH"

    ta Jason thicko with big plank says thanks.

    sometimes it really does pay to RTFM

  32. james says:

    Hi Jason,

    I keep getting segmentation fault errors with Xcache.
    I was wondering if my settings were the problem and if you could help me.

    I have a quad core with 4 gb memory server on centos 5 / apache 2.2 / php 5.2.5

    i used the following ini:

    zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

    xcache.admin.auth = On
    xcache.admin.user = "admin"
    xcache.admin.pass = "...hidden..."

    xcache.shm_scheme = "mmap"
    xcache.size = 256M
    xcache.count = 2
    xcache.slots = 64K
    xcache.ttl = 7200
    xcache.gc_interval = 300
    xcache.var_size = 128M
    xcache.var_count = 1
    xcache.var_slots = 8K
    xcache.var_ttl = 3600
    xcache.var_maxttl = 0
    xcache.var_gc_interval = 300
    xcache.test = Off
    xcache.readonly_protection = On
    xcache.mmap_path = "/tmp/xcache"
    xcache.coredump_directory = ""
    xcache.cacher = On
    xcache.stat = Off
    xcache.optimizer = Off

    xcache.coverager = Off
    xcache.coveragedump_directory = ""

    zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20060613/


    any ideas?

    also, the xcache admin page does show that its caching and working etc...
    but when i performing some benchmarks and i really don't see much difference.

    im using things like phpbb and vbulletin for benchmarks with ab and siege.

  33. Jason says:


    If you don't actually need the ZendOptimizer then get rid of those lines at the end; the same goes for the Ioncube loader. Also, what version of XCache are you using? If you've got my yum repo installed on your system then run a 'yum update' as I rolled out packages for 1.2.2 yesterday.

    As to the config you posted, I don't see anything specific that would be a problem, although your value for slots is WAY too high for most installations (I use 1K for most sites). I also doubt that you need 128MB in the var cache.

    Finally, as to performance, page load times are not a good measure. On a dynamic, database-driven web site most of the page load time is allocated to database queries, data transfer and browser rendering; only a tiny fraction is actually from PHP opcode compilation. The best measure would be to keep an eye on your system load. Of course, if the load is low to start with, you may not notice any appreciable decrease.

  34. james says:

    jason, first of all, thanks for the reply.
    i do need the ioncube and zendoptimize as some of my clients have sites utilizing those.
    and i am assuming they are the cause for the segmentation fault.
    if this is the case, is there a solution?

  35. Jason says:


    Using the ZendOptimizer, Ioncube loaders, and XCache (or any PHP cache) can cause problems. Try changing the order that they are loaded; that helps many users.

  36. Possum says:

    Where is the Zend Optimizer/Engine loaded? I've looked, but am befuddled (RHEL4) I disabled IonCube Loader, and my forum/site is fine. I want to take the next step to see if I can drop Zend as well. XCache 1.2.2 is working, and I am simply trying to trim down the memory utilization by killing off unnecessary programs/processes.

  37. Jason says:


    Zend is generally loaded from the last few lines in your /etc/php.ini file. Installing the Zend Optimizer may have relocated your php.ini file. You can find the exact location, along with the locations of any ancillary config files, near the top of your phpinfo().

  38. Possum says:

    Thanks Jason. I found it odd that it was not in the /etc/php.ini file, and I have scoured it. Maybe I don't need to worry about it. When I look closer, in my phpinfo, It does not show the Zend Optimizer, only the following:

    Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
    with XCache v1.2.2, Copyright (c) 2005-2007, by mOo

    I am pondering that I don't need to worry about then, as I had already gone through all the loaded *.ini files for PHP, and no reference to Zend could be found. But I could very well be wrong.

  39. Jason says:


    According to the output you posted you do not have the Zend Optimizer installed.

  40. barabashko says:

    first of all Jason thank you for the great REPO, im using it since yesterday, succesfully updated my mysql, apache, php with no problem at all ! 🙂

    trying to install xcache, but i have zend optimizer 3.3.0a to load some scripts

    when im reastarting httpd it loads cpu to 99%
    checked logs, and it says that

    [03-Feb-2008 05:21:07] PHP Fatal error: [Zend Optimizer] Zend Optimizer 3.3.0 is incompatible with XCache 1.2.2 in Unknown on line 0

    renamed /etc/php.d/xcache.ini to other file so i can load httpd again

    tryed to load it with php.ini modified with xcache setting and without it, with no succes

    how can i fix this ?

    sorry for my english, hope you get it 🙂

  41. Jason says:


    XCache 1.2.2 includes an update for dealing with uncachable content. Have you tried changing the load order? I would think that XCache would have to be loaded before ZendOptimizer and I don't believe that that would be the default.

  42. Paul says:

    Jason, first, thanks for your original post and all the work you've done to follow up on it!

    I'm curious to know if you're aware of XCache having any issues with Plesk? (Specifically 8.2 or 8.3)

    I have a dedicated server with Rackspace that's about to go live with a php-heavy site. Rackspace reports eacclerator is prone to segfaults with Plesk, and you note above that APC had some issues under load as well as segfaults.

    Any idea if XCache would be a better solution under Plesk? Any insight appreciated.

  43. Jason says:


    I use XCache on a Plesk 7.5.4 system (it's what runs this site) and I don't have any issues. I haven't tested it with a newer version of Plesk but I can't imagine that the result would be any different.

  44. Kenny says:

    I have installed XCache using your yum repo and restarted apache. Is that all I have to do to utilize the XCache PHP opcode caching? Or do I modify my files to use xcache_set/xcache_get? I was assuming those were only for var caching. Thanks for your help.

  45. Jason says:


    The defaults I set in the xcache.ini file will allow XCache to work out of the box for opcode caching. If you want to use it for more than that you will need to edit the config file and possibly your code.

  46. Snipervzln says:

    Hi Jason, thx a lot for this, you save my site; i was having server loads that you can't imagine (80+), and now everything it's back to normal. Just one question, it's posible to change the default administration page folder? Instead of html/xcache can i put it somewhere else? How i do it? Thanks in advance.

  47. Matt says:

    And I like this MD5 generator:


Check out what others are saying about this post...
  1. [...] those of you using it, the src.rpm for XCache 1.2.0 in my PHP Caching and Acceleration with XCache tutorial has been updated to fix a bug that might occur on some servers (see this ticket for more [...]

  2. りおてく says:

    xcache enabled with SELinux...

    I tried to install xcache in my server i......

This site is no longer updated. If you have a need for RHEL/CentOS LAMP Stack updates outside the normal channels, I recommend ART.