Possibly (best guess, by the PHP code I've seen) there is a great amount of storage in memory, either by dumping huge amounts of data in an array them sifting through them to output. Alternatively, it may be an intensive set of mysql queries. In the first case, there may not be much you can do short of revising the script to output as it runs:
while )(some process) echo (data); }
The downside of this is you get a page that partially loads, then loads more, then may still time out with half the page loaded.
In the second case, the script will need to be revised for more efficient queries.
Many would suggest "just increase your script timeout" but if you're on shared hosting this is just selfish (and lazy.) :-) Even if you're not, it's a sign you're using too many resources.
What I would do is first fix and optimize as above, then if it's still timing out, either cron job it or experiment with
fork [php.net]. What fork does is it spawns a child process in which you do intensive procedures that would otherwise timeout the browser. The parent process immediately returns a response and has the child's processid available ($pid in that example.) Then you listen for the $pid and when it dies, the process is done and can view any results.
An example might be
- Page with link/form to start process, grab $pid
- pass $pid to another page with a frameset. The framed document has an auto-refresh in the document to check the existence of the $pid (say, every 5 seconds)
- If the $pid exists, return # of records processed and "working" message
- if the $pid doesn't exist any more, return "done" message and display results.