Setting a script execution time limit
//This is an optimization. We assume than no step can take more than one year.
if($time_limit > 0)
$end_time = time() + $time_limit;
else
$end_time = time() + 365*24*3600; // One year
Adapted from 1C-Bitrix (from the CommerceML parsing class).