Artisan命令可能被缓存或运行了错误的命令 [英] Artisan commands possibly being cached or running wrong command

查看:32
本文介绍了Artisan命令可能被缓存或运行了错误的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我将网站移至新服务器以来,我遇到了一个奇怪的问题.旧服务器运行的是PHP 5.4,新服务器运行的是PHP 5.6.我在Laravel 4.2中有十几条Artisan命令,它们以不同的间隔通过cron运行.有时,它将运行错误的命令.我不知道它发生的频率,因为大多数人不提供任何输出,但是偶尔我会从Command Y收到错误通知,但是运行的命令是CommandM. apc.enable_cli opcache.enable_cli 设置为关闭.还有其他我应该查看的缓存设置,还是其他设置?

I'm having a strange issue since I've moved my website to a new server. The old server was running PHP 5.4, the new server PHP 5.6. I have over a dozen Artisan commands in Laravel 4.2 that run via cron at different intervals. Occasionally, it will run the wrong command. I don't know how often it happens since most don't give any output, but occasionally I'll get an error notification from Command Y, but the command that was run was Command M. apc.enable_cli and opcache.enable_cli are set to off. Are there any other caching settings I should be looking at, or a different setting?

推荐答案

事实证明这是一个编程错误,并且对Artisan的工作方式还不完全了解.

It turns out that it was a programming error, and an incomplete understanding of how Artisan works.

运行artisan命令时,Artisan会加载所有Artisan命令类,这些类在每个类上都运行__construct方法.然后它将触发正确的命令.我的问题是在Command Y的__construct()方法中有一些代码会随机失败.我将该代码移到了fire()方法,因此它仅在调用该特定命令时才运行.我通过在__construct方法中使用 Log :: debug("Running".implode('',$ _SERVER ['argv'])."from".__CLASS __); 进行了验证,然后移动那条线开火了.

When an artisan command is run, Artisan loads up all of the Artisan command classes, which runs the __construct method on each one. It will then fire the correct command. My issue was that I had some code in Command Y's __construct() method that would randomly fail. I moved that code to the fire() method so it will only run when that particular command is called. I verified this by using Log::debug("Running " . implode(' ', $_SERVER['argv']) . " from " . __CLASS__); in the __construct method, and then moving that line to the fire method.

这篇关于Artisan命令可能被缓存或运行了错误的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆