The correct use of the sleep function in php
Posted on 2014-09-30
I've written a script that successfully decompresses a JSON file and then parses it. I have 365 files, each one ranging from 15 - 30 MB.
It takes a little over 10 minutes per file and I want to be able to start it up, leave for the nite and come back with all the files that I've loaded into the directory sitting as apples of gold on trays of silver - everything decompressed and neatly parsed
I want to be wise / strategic in the way I craft my script so I give it a chance to "breathe" in between files so it doesn't time out.
I've got my max_execution_time set to 14400, but if I've got my for loop set up like this, can I incorporate the sleep dynamic so I give my code a chance to catch its breath in between files? And when I do that, is the page still operating in the context of the four hour window I've set, or does it going to "sleep" result in a situation where when it "wakes up," it's functioning as though it were just getting started?
Here's what I'm thinking:
foreach($arr as $file)
What do you think?