This is my function:
public static function GetFormattedMicroTime($timestamp = false) {
if(!$timestamp)
$timestamp = microtime(true);
return DateTime::createFromFormat('U.u',sprintf('%.f', $timestamp))->format('Y-m-d\TH:i:s.u');
}
This is how I call it (I'm calling it only from one point in my code):
$microtime = microtime(true);
$sinceLastLog = number_format($microtime - self::$lastLogTime,4);
self::$lastLogTime = $microtime;
return Utils::GetFormattedMicroTime($microtime) .'|'. $sinceLastLog .'| blah blah';
And I'm getting a lot of:
PHP message: PHP Fatal error: Call to a member function format() on a non-object
Can anybody help me troubleshoot?
EDIT:
I'm using php-fpm 5.4.28
i've changed my function a bit:
public static function GetFormattedMicroTime($timestamp = false) {
if(!$timestamp)
$timestamp = microtime(true);
$d = DateTime::createFromFormat('U.u',sprintf('%.f', $timestamp));
if ($d instanceof DateTime){
return $d->format('Y-m-d\TH:i:s.u');
} else {
error_log("Erreur date ! timestamp = $timestamp erreur =".print_r(DateTime::getLastErrors(),true));
return $timestamp;
}
}
now i'm getting in nginx log:
PHP message: Erreur date ! timestamp = 1403539343,372 erreur = Array
(
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 2
[errors] => Array
(
[10] => Unexpected data found.
)
)