30

Just a question related to OPcache cause I didn't understand it and find an answer on Google:

When we talk about userland caching, what does it mean? I know PHP is pre-bundled with the new Zend OPcache extension and that this extension caches op code into ram in order not to stress too much the processor which should convert to op code the PHP source at every request, but what about the APCu when they say that it implements userland caching?

What is userland caching? Is it possible to keep APCu and Zend OPcache together, or not? Should Zend OPcache be used instead of APCu?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
tonix
  • 6,671
  • 13
  • 75
  • 136

1 Answers1

34

APCu was really developed by Joe Watkins in response to OPcache. APC supports both opcode caching and data caching, but has been dogged with stability problems in support opcode caching since PHP 5.4. After Zend Inc opened the source of Opcache and placed it under the PHP licence, it became the core and preferred opcode cache from PHP 5.5. But it only supports opcode caching and not data caching.

Joe's APCu is in essence a stripped out version of APC that only includes the data caching code, and is designed to be used along side OpCache if you need data caching.

Note that whereas Opcode caching is transparent at a source code level, data caching is not. Your application needs to be coded explicitly to use it. (Though standard PHP apps such as Wordpress, Drupal, phpBB, MediaWiki, ... include this support by default).

TerryE
  • 10,724
  • 5
  • 26
  • 48
  • 3
    So APCu implements an in memory data caching functionality like Memcached caching system? Am I correct? – tonix Nov 30 '14 at 16:17
  • 7
    Similar but different in that Memcached is out-of-process and RPC-capable so is clusterable and intrinsically more scalable -- albeit at a greater per-call overhead. APCu uses a shared memory region and the PostgreSQL spinlock library so most API calls are in-process with no waits so are extremely lightweight -- but not scalable outside the server. – TerryE Dec 01 '14 at 19:44
  • Thank you for your response and explanation! – tonix Dec 02 '14 at 14:58
  • 3
    Spinlocks are an option, not the default. rwlocks are default, mutex fallback to that, spinlocks fallback to process shared mutex. – Joe Watkins Dec 05 '14 at 15:04
  • Thanks for the clarification Joe. I was answering from memory. You use the pthread rwlocks if pthreads is available and only fallback o the PostgreSWL code it not. Either way the general comment thatmost API calls are in-process with no waits so are extremely lightweight -- but not scalable outside the server still applies :) – TerryE Dec 06 '14 at 17:34
  • "Your application needs to be coded explicitly to use it." This sounds a little bit like magic. As far as I understand, the APCu Cache must be "_installed_" as a PECL extension. The APCu functions can be used to save (cache) and load values by keys: `apcu_add('foo', $bar) ... apcu_fetch('foo')` – goulashsoup Aug 16 '19 at 17:01