I’m training a PHP script to run as a well behaved cron job. To escape infinite loops and such I’ve added set_time_limit.
As far as I know there is not finally clause functionality for PHP. I would like to have such functionality to cleanup, like unlinking files when the time limit is reached.
What would be an alternative way to accomplish this?
Bruce Aldridge already answered, how it can be reached.
I show you another way: RAII pattern (not to say that is better or worse)
Example:
If this class will be used for opening files, all files will be closed and unlinked on script termination. This example specially for your question – usually 1 object being used to give access to 1 resource.