Fotiman - 4:02 pm on Jun 11, 2012 (gmt 0)
It sounds as though you do have a potential race condition. For example:
1. User A visits the PHP page.
2. The PHP page locks the .js file
3. The PHP page writes to the .js file
4. The PHP page releases the lock on the .js file
5. User B visits the PHP page.
6. The PHP page locks the .js file
7. The PHP page writes to the .js file
8. The PHP page releases the lock on the .js file
9. User A's browser performs the HTTP request for the .js file and gets the version meant for User B
10. User B's browser performs the HTTP request for the .js file and also gets the version meant for User B.
It's a very small window, but none the less, there IS the potential for error.
Note, this is different from multiple users requesting the same php page, because each request is tied to a particular session. In this case, though, you're generating a .js file which is going to be requested via a separate HTTP request. A PHP page contains code that processes a request and generates output specific to the session, but a request to a .js file is only going to fetch the latest version of that file from the server, which in your case may get over written.