Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to use instead of apc user data cache in php 5.5?

Tags:

php

apc

PHP 5.5 includes zend opcache by default, which basically means that almost nobody will use APC.

But what to use instead of the user data cache part of APC (apc_store & apc_fetch & similar)?

One use case where I really like to use APC user data cache are "versions" of static assets (javascript, css..). Whenever I reference static file, I add hash of its content into the url (e.g. <script src=/script.js> will became <script src=/script.js?v=hash>), so that browser always uses current version and can cache it permanently.

I can imagine using redis or memcache to store the hashes of static files, but it seems silly to ask another process over network or socket just to get a hash of file content. APC user data cache (which is in shared memory and accessing it is almost as fast as accesing php variable) seems just the right thing to use for such data.

So the question is: what to use in php 5.5 to cache small bits of data instead of APC?

like image 902
m6k Avatar asked Jun 28 '13 17:06

m6k


People also ask

What is APCu in PHP?

APCu is an in-memory key-value store for PHP. Keys are of type string and values can be any PHP variables. APCu only supports userland caching of variables. APCu is APC stripped of opcode caching. The first APCu codebase was versioned 4.0.

What is APC user cache?

The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.


2 Answers

Starting from PHP 5.5 the APC user data storage is packaged separately as PECL APCu.

  • Source code: http://pecl.php.net/package/APCu
  • MacOS homebrew package is php55-apcu (brew install php55-apcu)
  • Debian/ubuntu is called php5-apcu (apt-get install php5-apcu)
  • Fedora/RedHat is called php-pecl-apcu (yum install php-pecl-apcu)
  • Windows - use precompiled APCu dll - follow instructions provided in the answer below.

This allows you to use all user cache functions, such as apc_store(). It will also return true for extension_loaded('apc') - this means that all libraries depending on APC will work similarly to PHP 5.4.

like image 81
Artur Bodera Avatar answered Oct 12 '22 05:10

Artur Bodera


I recently dealt with this question after upgrading from php 5.3 to php 5.5 beta 2.

I looked at Memcache and Redis. Depending upon whom you ask, the performance between the two is approximately the same. Some claim that Redis is marginally faster. However, Redis has a lot more features than Memcahe so I decided to go with Redis.

For a PHP client, I chose Phpredis over Predis. Phpredis is a C extension whereas Predis a pure PHP implementation. Thus, Phpredis is generally faster.

I'm primarily using Redis to cache and retrieve serialized objects. I started the project I'm currently developing in PHP 5.3 with APC. I'm continuing to develop the project with php 5.5 and Redis. While I don't have benchmark statistics, I can tell you that the app "feels" faster. This is likely due to performance enhancements in php 5.5 as opposed to APC user cache verses Redis. Either way, I'm happy with my choice.

I hope that helps. Good luck and happy hacking :-)

like image 6
Neil Girardi Avatar answered Oct 12 '22 03:10

Neil Girardi