Take a look at merlyn's Watching long processes through CGI. It might be helpful.
In reply to Re^3: Using exit by revdiablo in thread Using exit by Anonymous Monk