Adergaard
Adergaard

Reputation: 61

PHP: Using APC as general cache, XCache as opcache, possible?

I'm really intreagued by the general cache aspects of APC and want to use it in my code (this I know how to do, this is not the problem).

However, I'm using XCache as opcache now and want to continue to do so since I have it tweaked "just right" for my particular needs.

The reason I want to use APC cache as general cache is that I'm not happy with PEAR::Cache_Lite from Pear in terms of using it for variable caching as it stores it on the disk, and disk I/O is a bottleneck whereas RAM is not and APC stores variables in RAM, not in files on the disk.

So, anyone have any experience or knows if it is possible to setup APC to only run as general cache (being called via it's API in my PHP Code, similarly to that of PEAR::Cache_Lite) while I maintain another opcache (in my case, xcache).

Thanks.

Upvotes: 6

Views: 3359

Answers (5)

kenorb
kenorb

Reputation: 166879

You can use both caches, however they both overlap in terms of features. So ideally you should configure APC to cache only the files, and XCache as OPCache. Please check the following comparison of features:

Comparison of features for PHP accelerators such as APC, eAccelerator, XCache, Zend Opcache

For PHP >= 5.5 APC has been discontinued, therefore you should use XCache or Zend Opcache as your main PHP accelerator for the caching.

Upvotes: 1

Nir
Nir

Reputation: 25369

Xcache works also as a general cache. Just like APC. Just use Xcache!

mixed xcache_get(string name)
bool  xcache_set(string name, mixed value [, int ttl])
bool  xcache_isset(string name)
bool  xcache_unset(string name)
bool  xcache_unset_by_prefix(string prefix)
int   xcache_inc(string name [, int value [, int ttl]])
int   xcache_dec(string name [, int value [, int ttl]])

Here is the API

Upvotes: 5

Alister Bulman
Alister Bulman

Reputation: 35169

Having the two caches trying to run at the same time would not be possible. They would be attempting to hook into the same system. Choose one.

There now follows the standard plug for the other technology that you don't use:

Technically, and speed-wise, there's not much in it, though I have seen reports that APC does better at including files and particularly with such techniques as autoloading (eg, with Zend_loader). APC does have easy of access (pecl install...), and it's a 'more official' PHP project then the other caching system.

I've used APC to great affect, for that standard opcodes and also for a significant number of variables, with TTLs ranging from 30 seconds (how many people online right now), to 24hrs, or more (database table meta-information).

Upvotes: 0

Ole Helgesen
Ole Helgesen

Reputation: 3241

If apc.cache_by_default if off and apc.filters doesn't match anything, PHP files will not be cached by APC.

In your config:

apc.cache_by_default = Off

http://www.php.net/manual/en/apc.configuration.php#ini.apc.cache-by-default

Upvotes: 4

Corey Ballou
Corey Ballou

Reputation: 43547

The runtime configuration settings have the following:

apc.optimization 0 "The optimization level. Zero disables the optimizer, and higher values use more aggressive optimizations. Expect very modest speed improvements. This is experimental."

http://www.php.net/manual/en/apc.configuration.php#ini.apc.enabled

Upvotes: 0

Related Questions