Slightly embarrassingly, my migration script has some kind of memory leak in it. It's a script I'll use once and just doesn't warrant the time of tracking down the leak.
It has to process over 8000 records, do quite a lot to each one (some have albums of photos attached to them that require significant work), and set them all up in a new database. So far, I would try running the script and after a few hundred records it would time out.
My solution was to create a bash script (although you could do this in any language) that checked to see how my PHP migration script stopped and re-ran the script if it wasn't stopped correctly.
#!/bin/bash /usr/bin/php migration.php while [$? != 0]; /usr/bin/php migration.php done
PHP programs return 0 when they end properly. So if it's anything else, just re-run the same script. The PHP script has a pointer that keeps track of its place so it starts where it left off. Simple as that.