From bff38bea6823ed6989f4a52299eb85993eeac363 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 16 Aug 2009 00:59:22 +0000 Subject: [PATCH] PHP functions encapsulated: - getMilliTime() introduced which encapsulates gettimeofday() - idle() introduced which encapsulates several sleep functions --- .../main/class_BaseFrameworkSystem.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) 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] -- 2.39.2