Zh0r
Zh0r

Reputation: 565

Laravel 4: Why is my artisan command called 5 times in succession?

Today I bumped into something strange regarding an Artisan Command's lifecycle.

  1. I added an artisan command named cronjobs:MyCommand.
  2. Created the necessary files and classes.
  3. Class MyCommand extends BaseCommand.

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?

Upvotes: 3

Views: 415

Answers (2)

Mahen Nakar
Mahen Nakar

Reputation: 394

Issue seems still not fixed.. I had also creaed a basecommand with __destruct method which is gettigng executed multiple times.

I created a shutdown method in my basecommand and calling at the end of mycommand.

Upvotes: 0

Zh0r
Zh0r

Reputation: 565

Further testing with Symfony 2's command class showed that this is a problem native to Symfony 2, not so much with laravel 4.

Using a constructor/destructor in an artisan command's class (or its parent) in any useful way seems impossible at this point in time.

Any input is still highly appreciated!

Upvotes: 1

Related Questions