views:

131

answers:

2

When I first meet PHP, I'm amazed by the idea Sharing-Nothing-Architecture. I once in a project whose scalaiblity suffers from sharing data among different HTTP requests.

However, as I proceed my PHP learning. I found that PHP has sessions. This looks conflict with the idea of sharing nothing.

So, PHP session is just invented to make counterpart technology of ASP/ASP.NET/J2EE? Should high scalable web sites use PHP session?

+1  A: 

The default PHP model locks sessions on a per-user basis. That means that if user A is loading pages 1 and 2, and user B is loading page 3, the only delay that will occur is that page 2 will have to wait until page 1 is done - page 3 will still load independently of pages 1 and 2 because there is nothing shared for separate users; only within a given session.

So it's basically a half-and-half solution that works out okay in the end - most users aren't loading multiple pages simultaneously; thus session lock delays are typically low. As far as requests from different users are concerned, there's still nothing shared.

Amber
No - certain session handlers might do that (I'm thinking particularly for file based session handling on Microsoft) and even then if you're on such a platform you can always do an explicit session_comit()
symcbean
@symcbean, do you mean, in Windows file based session handling, all HTTP requests would go through one single lock for different session?I gave it a try. Access my script (in my question) with Firefox and IE. They are two different sessions, and they don't block each other. I'm not sure whether my understanding of your comments is correct.
Morgan Cheng
I'm not sure what symcbean is referring to either.
Amber
@Morgan - No - one session -> one data file -> one lock - but the same serverside session can be associated with more than one browser session - and even for a single browser window there can be multiple concurrent requests
symcbean
+1  A: 

PHP allows you to write your own session handler - so you can build in your own semantics using the default hooks - or, if you prefer you could use the built in functionality to generate the session id and deal with the browser side of things then write your own code to store/fetch the session data (e.g. if you only wanted the login page and not other pages to lock the session data during processing, then this is a bit tricky though not impossible using the standard hooks).

I don't know enough about the Microsoft architecture for session handling to comment on that, but there's a huge difference in the way that PHPs session handling, and what actually gets stored in the session compared with J2EE.

Not using sessions in most of your pages will make the application tend to perform a lot faster and potentially scale more easily - but you could say that about any data used by the application.

C.

symcbean
Morgan Cheng