【问题标题】:An error occurred when executing the ""cache:clear --no-warmup"" command执行“cache:clear --no-warmup”命令时出错
【发布时间】:2016-08-05 04:29:34
【问题描述】:

我是 php 和 symphony 的新手。我正在尝试使用 composer 安装一些 php 包。我收到此错误:

脚本 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache 处理 post-install-cmd 事件因异常而终止

[RuntimeException] 执行时出错 ""cache:clear --no-warmup"" 命令:

[Symfony\Component\Debug\Exception\ContextErrorException]

Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the

date.timezone 设置或 date_default_timezone_set() 函数。在 万一你使用了这些方法中的任何一种,你仍然得到这个 wa
rn ing,您很可能拼错了时区标识符。我们现在选择时区“UTC”,但请将 date.timezone 设置为 选择您的时区。

关于什么可能导致这种情况的一些想法?

【问题讨论】:

  • 您没有在 php.ini 中设置默认时区 - 请记住,您的 Web 服务器通常有一个 php.ini,而 php cli 则有另一个
  • 谢谢,有帮助!

标签: php symfony composer-php


【解决方案1】:

这是因为 php.ini 没有定义默认时区。要使更改服务器独立,您可以通过将以下代码添加到 AppKernel.php 内的 AppKernel 类轻松解决该问题:

public function __construct($environment, $debug)
    {
        date_default_timezone_set('Europe/Berlin');
        parent::__construct($environment, $debug);
    }

Europe/Berlin 是您的时区。一旦完成,在发出任何命令之前,您必须至少加载一次页面,以便 AppKernel 类构造函数至少运行一次。之后您可以运行正确的命令,它应该可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 2018-05-12
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多