From comment section in php.net for set_time_limit
<?php
set_time_limit(60);
ob_start();
function shutdown () {
$out = ob_get_clean();echo $out; // echo output if required
// do your processing code
}
register_shutdown_function('shutdown');
// your code
?>