From: Roland Häder Date: Sun, 16 Aug 2009 00:59:22 +0000 (+0000) Subject: PHP functions encapsulated: X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=bff38bea6823ed6989f4a52299eb85993eeac363 PHP functions encapsulated: - getMilliTime() introduced which encapsulates gettimeofday() - idle() introduced which encapsulates several sleep functions --- diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 91d3d025..cb52a1c3 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -1118,6 +1118,46 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { public final function getIteratorInstance () { return $this->iteratorInstance; } + + /** + * "Getter" as a time() replacement but with milliseconds. You should use this + * method instead of the encapsulated getimeofday() function. + * + * @return $milliTime Timestamp with milliseconds + */ + public function getMilliTime () { + // Get the time of day as float + $milliTime = gettimeofday(true); + + // Return it + return $milliTime; + } + + /** + * Idles (sleeps) for given milliseconds + * + * @return $hasSlept Wether it goes fine + */ + public function idle ($milliSeconds) { + // Sleep is fine by default + $hasSlept = true; + + // Idle so long with found function + if (function_exists('time_sleep_until')) { + // Get current time and add idle time + $sleepUntil = $this->getMilliTime() + $milliSeconds; + + // New PHP 5.1.0 function found + $hasSlept = time_sleep_until($sleepUntil); + } else { + // My Sun Station doesn't have that function even with latest PHP + // package. :( + usleep($milliSeconds * 1000); + } + + // Return result + return $hasSlept; + } } // [EOF]