|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Dec 06, 2012 2:14 pm Post subject: Small improvement for Smarty class constructor |
|
|
Code: | $this->start_time = version_compare(phpversion(), '5.4.0', '<')
? microtime(true)
: $_SERVER['REQUEST_TIME_FLOAT']; |
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Dec 06, 2012 2:26 pm Post subject: |
|
|
Actually, I'm using more convoluted variant of this code in my overloaded constructor.
Code: | if(defined('toolPageGenerationStarted'))
{
$this->start_time = toolPageGenerationStarted;
}
else
{
$this->start_time = version_compare(phpversion(), '5.4.0', '<')
? microtime(true)
: $_SERVER['REQUEST_TIME_FLOAT'];
} |
toolPageGenerationStarted constant is defined very early in script execution (in fact, it is part of my debugging framework, and included before any other scripts, if available).
Not that it matters for 5.4, but for earlier versions you get more reliable results. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Dec 06, 2012 2:29 pm Post subject: |
|
|
Thats fine if you want the start time to be the float time of the server. You could also just test isset($_SERVER['REQUEST_TIME_FLOAT']) instead of trusting the PHP version for it. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Dec 13, 2012 4:52 pm Post subject: |
|
|
mohrt wrote: | Thats fine if you want the start time to be the float time of the server. You could also just test isset($_SERVER['REQUEST_TIME_FLOAT']) instead of trusting the PHP version for it. |
Do read the code, please. I'm not "trusting" PHP version. I'm checking for it.
$_SERVER['REQUEST_TIME_FLOAT'] was implemented in PHP 5.4. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|