I have the following construct of a customer admin backend, which does work fine in production but on local vagrant test mashine it is running into timeout.(I marked the row from error message in the script with a comment).
I already increased the execution time to 300 from 30 but it hits the same error. So I am assuming the while loop is running endlessly?!
Cause the the tempdate and datetime do not meet the constraint != View the timestamps in error logging for this. I did the same error logging on production It seems on production the dates are created like this (2019-03-28 16:30:14.000000) while on test they have micro seconds as well which are then different and do not match the while criteria of != to break the loop
Question:
Can someone please explain why date_create() does not give me micro seconds but on test it does causeing the while not work as intended?
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();
}
ERROR MESSAGE:
[28 Mar 14:14:48.572803 2019] [uncaught error] [type E_ERROR] [file /var/www/oxideshop/source/modules/comp/gg_analytics/application/controllers/admin/admin_gganalytics_view.php] [line 119] [code ] [message Maximum execution time of 300 seconds exceeded]
Error logging:
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)