How to increase timeout for a 30 minute (or longer) single PHP function?

I have a one-time use PHP script I use for importing old Website posts (tens of thousands of them). I've set the script up to run in small chunks, 500 posts at a time. But as the database gets bigger, the import takes longer. Since this is a one-time use script, on a dedicated server with a boatload of RAM, I'd like to be able to extend PHP's runtime (and memory use) to allow the script to run.

Is there (a) a way within the PHP script itself to temporarily allocate a pile of RAM and allow for a, say, 30-minute script run, or (b) a way to modify php.ini so that I could do the same thing?

I know I can boost memory allocation in php.ini, but I don't know how to increase timeout. I don't mind hacking the php.ini file, because once the script runs successfully, I'll just go back in and reset it.