douhuigan8063 2017-08-10 13:09
浏览 54
已采纳

Redis for PHP Sessions - 为什么在Web服务器上有这么多会话但在本地只有一个?

I've installed Redis to handle PHP sessions (and caching purposes). When I load the homepage of my website, the following happens.

On localhost

One session ID is generated.

$ redis-cli
127.0.0.1:6379> keys *
1) "PHPREDIS_SESSION:3g8sdqkj51btah10v88vapkr57"

On web server

10+ session IDs are generated.

$ redis-cli
127.0.0.1:6379> keys *
1) "PHPREDIS_SESSION:sgp4gop68st6iqmgnrti76tqn4"
2) "PHPREDIS_SESSION:2sstonql09hreokd14gba5csr2"
3) "PHPREDIS_SESSION:kv7cjhpgq8o2dkuglcg3rqj955"
4) "PHPREDIS_SESSION:2m07rtut3qt0k0ujuvftp0g3g3"

(... and about 10 more session keys)

The other thing is that for every refresh of the homepage, the redis server on the web host seems to instantiate around 2-10 new PHP sessions, while on localhost it just stays at one session all the time.

There's probably a good reason for this, and I'm hoping that anyone could explain this to me.

Could it have anything to do with the web page on the web server actually loading many external resources, which get their own session? Or could it be that I have configured something incorrectly? Both pages are identical in PHP code.

I'm not sure what more information I can provide for helping answer this question better, but please ask for anything.

  • 写回答

1条回答 默认 最新

  • dongwuxie7976 2017-08-11 09:10
    关注

    This is not a redis problem. The most probable reason is difference in session management settings in your local vs webserver php, do check the ini configuration primarily for session settings. Your webservers is creating new sessions on all requests, while localhost is respecting the existing session.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 计算机网络技术基础问题
    • ¥15 设置mac系统只能访问指定网站
    • ¥15 西门子博途 s7 1200控制三台步进电机
    • ¥15 基于非参数的方向距离函数求污染物影子价格(有偿)
    • ¥15 vue+element 生成table
    • ¥15 实验 4 FIFO 算法和 LRU 算法-C 程序实现
    • ¥30 电脑画面同步投屏,通过同wifi的方式投屏方法,接收投屏端不需要安装第三方软件,
    • ¥15 有偿拼接大疆精灵4RGB影像
    • ¥15 Arduino实现音频混响
    • ¥15 cuda.jit加速报错