That error message--"premature end of script headers"--doesn't
necessarily mean that your script died. It could also mean that
your script printed something out before it printed out the
HTTP headers. Could that be the case? Try running it from
the command line, using the "real server", and see what
gets printed out, and in what order.
If you're getting content before headers, that's probably
your problem.