Pros and cons of using memcached for PHP sessions

Besides the drawback of when you restart memcached all sessions are lost and users logged out, what are any other drawbacks for using memcached for storing PHP sessions data instead of files. Any security concerns? Is performance better using memcached instead of standard files on disk?


Although, many have been able to optimize database performance through the use of Memcached it may not be the best solution for every situation.

Some of the drawbacks of Memcached:

  • Size Requirement
  • Not much Documentation support
  • Volatility (If a Memcached server instance crashes, any object data stored within the session is gone)
  • Security (There is no authentication built into Memcached).
  • But still Memcached is a good choice in many apps because of following reasons:

  • Memcached can compensate for insufficient ACID properties and it never blocks.
  • Memcached is cross-platform
  • Cross-DBMS
  • Its Cheap
  • Lets look at the brighter side!


    Not a security concern specific to using memcached for sessions, but rather something I often come along: You absolutely must make sure that your memcached instances are either using unix sockets, or - if they're bound to a part - their port is blocked. Otherwise, people can just telnet in and view, modify and delete (session) data.

    Also, as the name implies, it is a caching solution, not a storage solution. As such, if you decide to use memcached for session storage, you ought to have it either database backed or file-storage backed, so if there is a cache miss (entry deleted due to time out, manual removal, flush or because the assigned memory was full and it got pruned), it can check a more persistent type of storage before saying "nope, it isn't there".

    链接地址: http://www.djcxy.com/p/11706.html

    上一篇: 缓慢UIViewController加载时间(慢ClientState警告)

    下一篇: 使用memcached进行PHP会话的优点和缺点