This one’s been in the hopper for a long time. Back in February, I came across, through Ajaxian, Marc Wandschneider’s “Troubles with Asynchronous Ajax Requests and PHP Sessions”, and Harry Fuecks’s ‘AJAX and Session “Race Conditions”‘. These are very interesting and well written articles about an often difficult to understand, debug, and combat problem: race conditions.
The responses in the comments are all over the place, from claims to that this is how its supposed to be, to this isn’t a problem with PHP it’s a problem with HTTP being stateless, to PHP doesn’t actually have this problem. The facts appear to be somewhat different. In general, everyone’s right, at least a little bit. As with many problems of this type, particularities of each environment can render different results.
One of the problem with race conditions is that it is often difficult to actually witness the ramifications of one when it happens, especially if you are not aware of it. If you’ve used PHP’s built-in, default session handling (that uses files), you’ll never come across the problem. However, things get interesting once you start using session_set_save_handler to write your own session handler.
Continue Reading »









