in reply to browser time out
The method I've previously used for jobs which take a long time (tens of seconds) to run is to generate a holding page ("Please wait while we foo...") which refreshes every five seconds or so, with the script checking each time it refreshes to see if the job has completed.