We have an Cron-Script, which detects – if some users got kicked out of our application.
We can detect this, if a specific value is 1 – but in the the stream, no new entries get set.
Scripts run every hour. Mostly non are detected. But since 2012-10-31 23:59:03 every user got detected. If i run the script on my local maschine or even on the same machine as the cron runs. Everything got handled as it should.
First things first, our script:
require_once ('cron_init.php');
ini_set('date.timezone', 'Europe/Berlin');
ini_set('max_execution_time', 30);
ini_set('memory_limit', -1);
error_reporting(E_ALL);
ini_set("display_errors", 1);
Zend_Date::setOptions(array('fix_dst' => true));
$userinfos = new Repricing_Dbservices_Userinfos();
$users = $userinfos->getUsersForRepricing();
$repricingstream = new Repricing_Dbservices_Repricingstream();
$error = new Repricing_Dbservices_Error();
if($users!==false AND count($users)>0){
$counter = 0;
$errCounter = 0;
$jetzt = new Zend_Date();
$jetzt->setTimezone('Europe/Berlin');
$jetzt = $jetzt->get(Zend_Date::TIMESTAMP);
foreach($users as $user){
$stream = $repricingstream->getStreamLimit($user);
$last = new Zend_Date($stream);
$last->setTimezone('Europe/Berlin');
$last = $last->get(Zend_Date::TIMESTAMP);
$diff = (($jetzt-$last)/60);
$error->setError(1, 'DIED', $diff, $user);
if($diff > 50 ){
$errCounter++;
$userinfos->setUserFree($user);
$error->setError(1, 'DIED', 'ANSTOSSEN', $user);
}
$counter++;
}
$error->setError(1, $errCounter, 'ANSTOSSEN_ALL', 'ALL');
}
Usually $diff >= 0 AND $diff <= 4 but, we detected, that $diff is always round about 381595. If we run it out of cron $diff is, as it should.
We also detected, that $jetzt is now ( as it should ) only $last is much more later. 381595 later. But that shouldnt be. The last stream-date is fully normal. We cant understand this behaviour of. Zend_Date with cron. Bevor 2012-10-21 23:59:03 the script run 2 weeks as it should. We cant explain, how come. Can you?
Consider this:
Now the real freaky part: on my PC it’s the second behavior that is default – i.e., when no additional params are given to Zend_Date constructor.
The point is, Zend_Date is a bit… too helpful when trying to parse datetime strings. For example, it’s taking the locale into account – but the locale both of server and client! And if the string cannot be parsed within this locale’s rules, it silently gives up – and tries to use another rule.
That’s why
2012-10-29was parsed asOctober, 29(despite of what locale suggested, as there’s no 29th month) – but2012-11-01becameJanuary, 11– and messed up your script big time. )