using both Opcache and Xcache
Asked Answered
M

1

8

I'm just wondering is it stupid to use both Xcache 3 with Zend Opcache at the same time to cache PHP files? I know that both do almost the same job, but not sure if that would make any difference on the performance and speed.

I want to speed up my php page load so that visitors don't need to wait long.

any thoughts on that?

Malone answered 22/6, 2014 at 18:14 Comment(9)
You can only serve 1 cached file to the visitor, so creating 2 is unnecessary overhead. You need to do some performance testing between the 2 and choose one.Prettypretty
ok, is there something else I can replace with either one to increase the performance or just that will do!! because I've seen that memcache doesn't do much anyways!!Malone
MEMCACHE is great if you can afford the RAM. If you can't afford the RAM, then I'd stick with file system based caching. Any way you look at it, you're going to hit the I/O on the disk.Prettypretty
Just because two things each make something faster than none, doesn't mean using both will make it faster still. Imagine trying to put two engines into one car: first, you've got to somehow connect them both to the wheels at the same time, and have them help each other rather than just snarling everything up.Lindstrom
Thanks@Prettypretty for the useful comments. I will try out memcache and see how things can work.Malone
well said @IMSoP. I guess you made your point clear. Thanks a lot. I will stick with one only and test memcache for now.Malone
Note that many users cache from a tmpfs in Linux which is the same as caching in RAM since tmpfs lies in RAM. RAM caching is ideal for commonly used files but many times, the file system will handle caching to RAM for you.Ubiquitous
There are lots of things you can look at, from running the latest version of PHP and configuring your web server carefully, to using memcached or Redis to store the results of complex queries or remote API calls, through to caching the final output with something like Varnish. Each of these is a whole topic in itself, and the first thing to decide is what's going to make the biggest difference for you, given the needs of your particular application, and the resources you have at your disposal.Lindstrom
Opcache works well with APCu and memcache. Don't mix xcache and opcache. Also don't bother with reverse proxy caches such as squid or varnish unless you are a reasonably experienced sysadmin. You will just get hopelessly tangled in knotsRoseleeroselia
R
6

To answer your question: Yes, you should not run xcache and Zend Opcache at the same time. If you do, you'll get undefined behaviours, most notably "cannot redeclare class XYZ" fatal errors. That happened to me after a systems upgrade, where the packet maintainer activated Zend Opcache along the already existing xcache installation.

As for the matter of which of both to use for opcaching, that depends on your specific code - I'd recommend setting up a test environment and firing up the Apache Benchmark or a similar tool to check the answer times.

On a default wordpress installation, I was able to get a speedup (uncached vs xcache) of about 5-7x, which is quite significant. If you really need more, you'll need to check out the other possibilities already mentioned in the comments like

  • using a loadbalancer and multiple application servers
  • using memcache or memcached to cache database queries and other load heavy operations
  • switching to another database system like a NoSQL system (be careful of the consequences)
  • changing your architecture to a static site with webservices providing interactive content
Responsory answered 21/2, 2015 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.