I would suggest running your script using the debugger to find out where it is hanging up.
If you have query string parameters you can send them in as command line args:
The n key will step thru your program line by line, s will step into a subroutine. You should easily be able to find the line causing the problem that way. Check the docs for the debugger, it's the way to go.