views:

66

answers:

3

We have a problem with PHP session when APC is enabled on our server.

The app works great without APC. However, since we enabled APC, the sessions seems to be getting mixed up when the server experiences heavy load, i.e. users are randomly logging on as another. Everything reverts back to normal once we disabled APC. We can't seem to find anyone with the same problem, except a related problem with these guys (set-cookie was being cached in MS ASP): http://msdn.microsoft.com/en-us/magazine/cc163577.aspx#S2

Anyone else has similar experience? Can you recommend any suggestions?

PS: We have all our sessions handled by files in php.ini. We are also running apache2.

A: 

well please verify that apc really mixes up data... the only possible i can think of when this could happen is when it gets full and does a stackoverflow. please check the usage and maby increase the cache size.

Joe Hopfgartner
We are fairly sure this is the case, although it is possible that this is a bug that only happens when two users access a function simultaneously. By having APC enabled, we can serve more req/s hence increases the probability for them to do so.
A: 

There is a problem that crops up with APC where custom session handling objects get destroyed before the session data is saved. It could be unrelated to your problem, but an explicit call to session_write_close before the regular PHP shutdown fixes that one.

Your problem sounds a bit different though, but I can confirm that issues do exist.

konforce
Thanks, we will look in to this as well.
A: 

Just to complete the post, we had success in reducing this problem with three things:

1) We made extra checks to make sure that the IP is matched to the session ID, and logout the user otherwise. We could then use this to track how often the problem occurs.

2) We switched to XCache and immediately saw lower number of confused session IDs. However, under very heavy load the problem rears its ugly head again.

3) We then double the memory for Xcache in the php config (xcache.size and xcache.var_size) and now the problem is gone.

So we suspect either APC or Xcache running out of memory was the problem. We're still waiting to see if this is a permanent solution.