I have a php script that for some reason sometimes either goes into an endless loop or it just fails & ends. Eitherway, the session is not released which causes other requests from the same session to wait endlessly.

What could cause this? How can my script run endlessly OR fail without releasing the lock on the session?

If the script goes into an endless loop it looks like it does so when I do a quite simple sql-query.

Any hints?