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.

    点赞 打赏 评论

相关推荐 更多相似问题