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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化