dpp78272 2011-02-05 15:04
浏览 77
已采纳

使用缓存系统进行会话存储?

Say I have a caching system that i can use for storing sessions:

// example i have a cache class
$memcached->add('key','value');
// then i can get the session from
$memcached->get('key');

What are the advantages and disadvantages of using caching (e.g. memcached, maybe Redis can fit in, or other things) for sessions rather than using PHP's built-in sessions?

  • 写回答

2条回答 默认 最新

  • duan01203 2011-02-05 15:19
    关注

    You should be able to have PHP store session data in Apache's runtime memory by setting session.save_handler to mm. However, to do this you need to compile PHP with the memory management module (--with-mm), which I don't think is available for Windows.

    If you want to use memcached or some other caching mechanism, then it'd probably be best to implement user-defined storage handlers using session_set_save_handler so you don't have to rewrite your session management code.

    If you do that, then I don't think there are any obvious disadvantages to storing session data in that way. The obvious advantage is speed.

    Edit: I came across this page which discusses, aside from speed, the main advantages/disadvantages of using memcached for storing sessions, namely:

    • It's easy to share sessions across multiple webservers without using sticky sessions.
    • However, memcached makes no promises of keeping the data up until expiration—only that the data will not be available after expiration. So if memcached is low on ram, hasn't been used lately, or the server goes down at all, the session data will be lost.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题