If you’re anything like me, you’ve probably created an infinite loop or two in your day. One misconception that I had however, was that a single script that entered an infinite loop was causing my entire server to get locked up, because I couldn’t reload the page or load any other page. I always just restarted my web server (Doh!)
Recently, I learned that the cause for this behaviour was completely different then what I thought. PHP employs session locking, so if you have a script that uses sessions, only one script can run at a time for a single user, since that script locks the session file and the other script has to wait for the file to be unlocked. This is another reason why I experience slow loading times when I utilize PHP scripts to load images or other files.
This problem can be solved however. Once you are past the point in your application in which you need to modify the session, you can call the function session_write_close(). This frees up the session file for the next script, and is an invaluable function once you know about it.