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 mmo能不能做客户端怪物
  • ¥15 osm下载到arcgis出错
  • ¥15 Dell g15 每次打开eiq portal后3分钟内自动退出
  • ¥200 使用python编写程序,采用socket方式获取网页实时刷新的数据,能定时print()出来就行。
  • ¥15 matlab如何根据图片中的公式绘制e和v的曲线图
  • ¥15 我想用Python(Django)+Vue搭建一个用户登录界面,但是在运行npm run serve时报错了如何解决?
  • ¥15 QQ邮箱过期怎么恢复?
  • ¥15 登录他人的vue项目显示服务器错误
  • ¥15 (标签-android|关键词-app)
  • ¥15 comsol仿真压阻传感器