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

4

28

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?

Unrig answered 28/6, 2013 at 17:39 Comment(1)
Use APCu, which is just the user cache part of APC.Wish
R
29

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

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.

Ritualism answered 9/1, 2014 at 9:26 Comment(7)
yum install php5-pecl-apcu -> no package availableCristycriswell
@FlyOn you're right. Thanks! I've corrected the package name for Fedora/Redhat ...Ritualism
Thank you!! I would've used opcache but the repository I'm working on needs apc. Life saver right here.Alvar
When migrating from APC to APCu, doesn't apc_store() become apcu_store() (etc)?Jukebox
@Jukebox nope :) it stays apc_store()Ritualism
Thanks, @ArturBodera! I think it goes either way - I think there's a setting somewhere to specify whether to use the original names or the APCu versions. Regardless, the original nomenclature is working well for me now, so I'll stick with it! :)Jukebox
I can't find the words to express my love for you right now! :OBanbury
C
6

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 :-)

Colner answered 3/8, 2013 at 18:6 Comment(0)
D
0

Nothing more to say. You got the correct answer already. I guess I can provide you with a link to tutorial to how to download and install APCu on XAMPP on Windows for php 5.5 and 5.6:

Link do download APCu for php build from 5.3 and higher: download APCu different versions

Installation tutorial: installation instructions (The newest version should be on the very bottom of the file list - use this one)

Also bear in mind that you will have two to choose from few options like 64 or 84 version as well as nts or ts and vc9 or vc11 (it can be different in your case) and of course the correct PHP version (in my case that would be PHP 5.6 for my xampp).

EXAMPLE:

if you want to pick right you have to run phpinfo() first and check for those parameters:

Zend Extension Build and Architecture

In my case that would be:

[Zend Extension Build:] API220131226,TS,VC11

[Architecture:] x86

That mean that in my case I would have to choose ACLu wchich contain in file name those parameters 5.6, TS, VC11, 86

file name to download: php_apcu-4.0.7-5.6-ts-vc11-x86.zip

Hope that clear things up for you.


Some aditional explanations on different PHP builds:

difference ts vs nts: TS refers to multithread capable builds. NTS refers to single thread only builds. Use case for TS binaries involves interaction with a multithreaded SAPI and PHP loaded as a module into a web server. For NTS binaries the widespread use case is interaction with a web server through the FastCGI protocol, utilizing no multithreading (but also for example CLI).

difference vc9 vs vc11 vs vc14: More recent versions of PHP are built with VC9, VC11 or VC14 (Visual Studio 2008, 2012 or 2015 compiler respectively) and include improvements in performance and stability.

  • The VC9 builds require you to have the Visual C++ Redistributable for Visual Studio 2008 SP1 x86 or x64 installed
  • The VC11 builds require to have the Visual C++ Redistributable for Visual Studio 2012 x86 or x64 installed
  • The VC14 builds require to have the Visual C++ Redistributable for Visual Studio 2015 x86 or x64 installed

difference 86 vs 64: The x64 builds of PHP for Windows should be considered experimental, and do not yet provide 64-bit integer or large file support.

Dunc answered 15/11, 2015 at 4:42 Comment(0)
S
-1

Take a look at the XCache opcode cacher, from the authors of lighttpd. It supports both php 5.5 and user data cache: http://xcache.lighttpd.net/wiki/XcacheApi

I didn't try it my self (still using APC and php 5.4).

Sweepings answered 13/12, 2013 at 9:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.