Skip to content
/ Memory Public
forked from e-oz/Memory

PHP Memory Cacher - best cachers in one interface, with nice features

Notifications You must be signed in to change notification settings

phpguru/Memory

 
 

Repository files navigation

PHP Memory Cacher

##Key-value storage in memory As a storage can be used:

All storage objects have one interface, so you can switch them without changing the working code.

##Features:

  • Tags for keys
  • Dog-pile and race-condition effects are excluded
  • Increment can work with arrays, strings and numeric values
  • MultiAccess class can be used for any resource, to gain access one write multiple read

##Usage: See demo.php to get documentation.

##Requirements: You can use each storage separately, requirements are individually for storages

###PHP version: 5.3+ (maybe 5.2+, not checked)

###For APCObject: APC should be installed, and this setting should be added in php.ini (or apc.ini if you use it)

  • apc.slam_defense = Off
  • recommended: apc.user_ttl = 0

###For Memcache: Memcache or Memcached PHP extension should be installed.
Memcache is not the fastest and most secure storage, so use it only when necessary. Read more

###For Redis: Redis server should be installed (in debian/ubuntu: "apt-get install redis-server"). Also, phpredis (if installed) can be used as client library - just use PhpRedisObject instead of default RedisObject.

###For SHMObject and MultiAccess: PHP should support shm-functions and msg-functions (--enable-shmop --enable-sysvsem --enable-sysvshm --enable-sysvmsg)
Should be used only in specific cases (e.g. mutexes), or when other extensions can not be installed.

#Storages comparison: APC is a very fast and easy to use storage, use it in most cases. If APC can not be used for caching data, or you just like Redis - use Redis. Redis and Memcache can be used for cross-process communication. Also, data in Redis storage will be restored even after server reboot. Don't want to install Redis (it's just 1 line in console :))? Use Memcache. If you can't install any third-party packages, you can use Shared Memory - but your PHP should be compiled with support of shmop-functions.

##Performance comparison

  • APC - best performance, let speed result of APC in benchmark is 1.
  • PhpRedis - speed 1.23
  • Redis - speed 1.6
  • Shared memory - speed 130
  • Memcache - speed 192 (slowest)

TODO:

  • Atomize increment operation

Look at the comments in demo.php for additional info. Ask, what you want to see commented.

License: MIT

About

PHP Memory Cacher - best cachers in one interface, with nice features

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published