0

我有一个客户管理后端的以下构造,它在生产中运行良好,但在本地无业游民测试机器上它运行到超时。(我在脚本中用注释标记了错误消息中的行)。

我已经将执行时间从 30 增加到 300,但它遇到了同样的错误。所以我假设while循环无休止地运行?!

导致 tempdate 和 datetime 不符合约束!= 在错误日志中查看时间戳。我在生产中进行了相同的错误日志记录似乎在生产中日期是这样创建的(2019-03-28 16:30:14.000000),而在测试中它们也有微秒,然后它们是不同的并且不符合 while 标准of != 打破循环

问题:
有人可以解释为什么date_create()没有给我微秒但在测试中它确实导致 while 不能按预期工作?

public $_datefrom = null;
public $_dateto = null;
public function __construct () {

        //(...deleted stuff to post this.....)
        $datetime1 = date_create($this->_datefrom);
        $datetime2 = date_create($this->_dateto);

        $tempdate = date_create($this->_datefrom);
        $tempdateto = new DateTime();

        $this->_aIntervalDateArray[$tempdate->format('d.m.Y')] = array();
        ini_set('max_execution_time', 300); //300 seconds = 5 minutes
        while($tempdate != $datetime2) {
        print_r("tempdate "); var_dump($tempdate); print_r(" datetime2 ");var_dump($datetime2);print_r("<br>");// debugging
            $tempdate->modify('+1 day'); // row 119  <<<<<<<<
            if($tempdate <= $tempdateto ) {
                $this->_aIntervalDateArray[$tempdate->format('d.m.Y')] = array();
            }
        }

        $this->_datefrompast = $datetime1->modify('-1 year')->format('Y-m-d');
        $this->_datetopast = $datetime2->modify('-1 year')->format('Y-m-d');


        $datetime1_past = date_create($this->_datefrompast);
        $datetime2_past = date_create($this->_datetopast);

        $tempdatePast = date_create($this->_datefrompast);

        $this->_aIntervalDateArrayPast[$tempdatePast->format('d.m.Y')] = array();

        while($tempdatePast != $datetime2_past) {
            $tempdatePast->modify('+1 day');
            if($tempdatePast <= $datetime2_past ) {
                $this->_aIntervalDateArrayPast[$tempdatePast->format('d.m.Y')] = array();
            }
        }

        $interval = date_diff($datetime1, $datetime2);

        $this->_dateinterval = $this->days_between() + 1;

        $this->_user = $oUser = $this->getUser();

        parent::__construct();
    }

错误信息:

[2019 年 3 月 28 日 14:14:48.572803] [未捕获的错误] [类型 E_ERROR] [文件 /var/www/oxideshop/source/modules/comp/gg_analytics/application/controllers/admin/admin_gganalytics_view.php] [第 119 行] [代码] [消息超过300秒的最大执行时间]

错误记录:

tempdate
/var/www/oxideshop/source/modules/comp/gg_analytics/application/controllers/admin/admin_gganalytics_view.php:145:
object(DateTime)[38]
  public 'date' => string '2019-03-28 15:13:20.613671' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Berlin' (length=13)

datetime2

/var/www/oxideshop/source/modules/comp/gg_analytics/application/controllers/admin/admin_gganalytics_view.php:145:
object(DateTime)[37]
  public 'date' => string '2019-03-28 15:13:20.613669' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Berlin' (length=13)


tempdate

/var/www/oxideshop/source/modules/comp/gg_analytics/application/controllers/admin/admin_gganalytics_view.php:145:
object(DateTime)[38]
  public 'date' => string '2019-03-29 15:13:20.613671' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Berlin' (length=13)

datetime2

/var/www/oxideshop/source/modules/comp/gg_analytics/application/controllers/admin/admin_gganalytics_view.php:145:
object(DateTime)[37]
  public 'date' => string '2019-03-28 15:13:20.613669' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Berlin' (length=13)
4

0 回答 0