Reputation: 565
I have noticed that multiple users per day are being assigned the same session_id. I am using php 7.2 now, but looking back into the history of user sessions this has been happening since I was using php 5.4.
I am just using php defaults of session_start()
, no custom session handler.
I have read that the session_id
is a combo of the client ip and time, but give that I am using a load balancer, that might be limiting the randomness of the ip_addresses
?
What is the proper way to increase the uniqueness of session_ids to prevent collisions when using a load balancer?
Upvotes: 4
Views: 1922
Reputation: 3664
Assuming you're running PHP-FPM on each web node, but I guess #2 and #3 would probably work running PHP as an Apache plugin as well.
You've got a few options here:
Number three is probably the best option in most cases.
Upvotes: 1
Reputation: 239
If you are using Nginx you may want to check if FastCGI micro-caching is enabled and disable it. This has caused some errors before noted in PHP.net developers bugs listings in PHP 7.1 running nginx
Bug #75496 Session ID Collision happened few times
After the first case [of collision] we changed a hash entropy php settings in php.ini so session_id is now 48 chars but it didn't help to prevent second case.
Solution:
FastCGI micro caching at nginx that cached 200 responses together with session cookies. Of course maybe it was set wrong at our server, but its definitely has nothing to do with PHP.
Please see: https://bugs.php.net/bug.php?id=75496
Upvotes: 1