Today I bumped into something strange regarding an Artisan Command's lifecycle.
- I added an artisan command named
cronjobs:MyCommand
. - Created the necessary files and classes.
- Class
MyCommand
extendsBaseCommand
.
BaseCommand
is something I put up to benchmark command line operations.
It consists of a constructor and destructor. The constructor keeps track of
the starting time of the operation, the destructor logs the current time minus
the starting time in a log table.
To my surprise I found out that the __destruct()
function on my BaseCommand
is
called 5 times in total every time I issue the cronjobs:MyCommand
via artisan.
Is this normal behavior and if so how am I supposed to take care of logging instead?