Well, you could just create a small script and call it from the cron (or task scheduler for windows). No php really needed...
But if you wanted to do it through php, there are some classes out there to do it already that you could just as easily put in the cron.
Also, max_execution_time can be changed at run time using ini_set(max_execution_time, $newTime);