
I know, this is far more work to implement, but it is the better way to do it.

Even if the server crashes and restarts, as long as the database is intact and the script runs again, everything should go as planned. Then that script could do this for you with an accurary of about a minute, which should be enough. How would that work? Suppose you execute a PHP script every minute, and you have a database entry that tells you which resource to allocate at a certain start time and deallocate at a certain expire time. I would start with 3590 seconds and make sure that always works.įinally: What are the alternatives? Clearly this could be a cron job. You have to leave some time for DigitalOcean to execute stuff and log the time. Then there's the problem that you want to sleep for exactly 3599 seconds, so that you're only charged one hour. This is under the assumption that FALSE is -1. If the call is interrupted by a signal, sleep () function returns a non-zero value. The sleep ( ) function accepts seconds as a parameter and returns TRUE on success or FALSE on failure.

A better sleep would be: $remainingTime = 3590 The sleep () function in PHP is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds. Not much you can do about that, given this script.Īlso, the sleep() itself might get interrupted, causing it to sleep much shorter than you want. I am worried that the script might get interrupted, and you will never delete the droplet. It sleeps for the given number of seconds. Note that sleep() should not have $time as an argument. You would need to make sure your script can run, at least, for that long.
PHP SLEEP 1 MINUTE CODE
It doesn't look like a good idea, but the code is so simple, nothing can compete with that.
