duandai7601 2013-08-30 15:41
浏览 36
已采纳

Laravel 4:为什么我的工匠命令连续被召唤5次?

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?

  • 写回答

2条回答 默认 最新

  • doushi1900 2013-09-09 09:52
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿