The issue here is that your loop is endless. You can just extend the maximum execution time like this:
ini_set('max_execution_time', '300'); //300 seconds = 5 minutes
Or you could use this to temporarily extend the time limit.:
set_time_limit(300);
I hope this helps.