PHP functions encapsulated:
authorRoland Häder <roland@mxchange.org>
Sun, 16 Aug 2009 00:59:22 +0000 (00:59 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 16 Aug 2009 00:59:22 +0000 (00:59 +0000)
- getMilliTime() introduced which encapsulates gettimeofday()
- idle() introduced which encapsulates several sleep functions

inc/classes/main/class_BaseFrameworkSystem.php

index 91d3d0253b95d7419644c9b21a8a704ef9b56f19..cb52a1c391570406fcf06a3b9fedaf0b7ced8b75 100644 (file)
@@ -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]