Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use APC AND memcached on the same server?

Tags:

php

memcached

apc

I am using memcache for cacheing objects, but would like to add in addition an opcode accelerator like APC. Since they both involve cacheing, I am not sure if they will be "stepping on each others toes", i.e. I am not sure if memcache is already an OP code accelerator.

Can someone clarify? I would like to use them both - bit for different things. memcache for cacheing my objects and APC for code acceleration

like image 679
Stick it to THE MAN Avatar asked Dec 20 '09 08:12

Stick it to THE MAN


People also ask

Can Memcached be used as a database?

Unlike databases that store data on disk or SSDs, Memcached keeps its data in memory. By eliminating the need to access disks, in-memory key-value stores such as Memcached avoid seek time delays and can access data in microseconds. Memcached is also distributed, meaning that it is easy to scale out by adding new nodes.

Is Memcached still used?

Memcached was created in 2003 and written in perl before being rewritten in C. Orginally created for livejournal it became one of the goto stack enhancements of the Web 2.0 era. It's still in use by very large web properties such as Youtube, Reddit, Facebook, Pinterest, Twitter, Wikipedia and more.

Is memcached a server?

Memcached is a server side caching system that is free and open source, and can be installed on any VPS or dedicated server. A caching system can dramatically improve the performance of your website.

Is memcached a relational database?

It stands for a non-relational or non-SQL. Memcached and Redis are categorized as NoSQL.


2 Answers

Memcache is more along the lines of a distributed object cache vs something like APC or XCache, which stores PHP bytecode in memory so you avoid having to parse it each time. Their main purposes are different.

For example, if you had a very CPU intensive database query that people often requested, you could cache the resulting object in memcache and then refer to it instead of re-running that query all the time.

APC & XCache do have similar object caching features, but you are limited to the host machine. What if you wanted 10 different servers to all have access to that one object without having to re-do the query for each server? You'd just direct them to your memcache server and away you go. You still get a benefit if you only have a single server because using memcache will help you scale in the future if you need to branch out to more boxes.

The main thing to consider is if you think your app is going to need to scale. Memcache has more overhead since you have to use a TCP connection to access it, versus just a function call for APC/Xcache shared objects.

However, Memcache has the following benefits:

  • Faster than the disk or re-running query.
  • Scales to multiple servers.
  • Works with many different languages, your objects are not locked into PHP + APC/Xcache only.
  • All processes/languages have access to the same objects, so you don't have to worry if your PHP child processes have an empty object cache or not. This may not be as big a deal if you're running PHP-FPM though.

In most cases, I would recommend caching your objects in memcache as it's not much harder & is more flexible for the future.

Keep in mind that this is only regarding caching objects. Memcache does NOT have any bytecode or PHP acceleration features, which is why I would run it side-by-side with APC or Xcache

like image 72
Klinky Avatar answered Oct 15 '22 09:10

Klinky


yes you can use them both together at the same time.

like image 4
nickf Avatar answered Oct 15 '22 09:10

nickf