0

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.

minitauros
  • 1,920
  • 18
  • 20
  • 1
    The session file count is an indicator for the number of different things/devices that are connected to your webpage, be it robots, spiders, advertising connections, 3rdparty stuff, etc. – Martin Aug 10 '17 at 13:12
  • Well if I reload the homepage 20 times, I end up with 200+ session IDs in my Redis db. And I am just one user. Say 10 000 users visit the home page on one day, and they all cause 10 sessions to be instantiated, that means 100 000 sessions for the home page alone. Say they visit 5 pages each, it might mean 500 000 sessions / day. Is this a realistic estimation / scenario? How do websites that have 10 000 visitors per hour handle this? Cause this sounds like a lot of data to me. – minitauros Aug 11 '17 at 07:40
  • Does this help: https://stackoverflow.com/questions/15911817/session-start-creates-new-session-every-refresh – Martin Aug 11 '17 at 09:29

1 Answers1

0

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.

DhruvPathak
  • 42,059
  • 16
  • 116
  • 175
  • You were right, I was wondering what was causing it, but when I changed the session cookie domain (`session.cookie_domain` in php.ini) to include all subdomains, the issue was resolved. – minitauros Aug 11 '17 at 10:52