You could try extending the server timeout on top of the page:
set_time_limit(0);
a '0' time limit is actually unlimited. One possible issue with this is that some servers won't let you change the time limit for scripts. When that is the case it could be difficult to solve without changing hosting providers.