Lars Hansen
Lars Hansen

Reputation: 105

Giving each of my not-logged-in users a unique session-id in cookies

I need something like a session-id. I will need to track a couple of thousand users visiting a website. For load-balancing (multiple instances of PHP and NGINX) I will unfortunately not be able to use session_start() and capture the sessionid because it needs to span across multiple webservers.

These users are not logged in, so I will not know anything about them, except for their browser, ip and plugins.

I was thinking maybe using APC, and do something like apc_store('count', 1);

And give the current user the id = 1.

The next user will get apc_fetch('count')+1, but I think that will be very slow, and probably also contain race-conditions.

Upvotes: 1

Views: 475

Answers (1)

Pascal MARTIN
Pascal MARTIN

Reputation: 401172

To solve the problem of "multiple servers" with sessions, you could store your sessions in something else than the file system.

For example, you could :

  • Store sessions in a database, shared by all webservers
  • Or store sessions in a memcached cluster (better solution -- and pretty easy)


A couple of interesting links :

Upvotes: 3

Related Questions