]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/System.php
Replace "notice" calls
[friendica.git] / src / Core / System.php
index dbff4bf3f5cb5f5d21c2bd537a230b315c30bbfe..0c1e499d939395ac82ec2c5a05451d9873da95a1 100644 (file)
@@ -323,12 +323,12 @@ class System
         * After finishing the process is getting killed.
         *
         * @param string $content
-        * @param [type] $responce
+        * @param string $type
         * @param string|null $content_type
         * @return void
         */
-       public static function httpExit(string $content, string $responce = Response::TYPE_HTML, ?string $content_type = null) {
-               DI::apiResponse()->setType($responce, $content_type);
+       public static function httpExit(string $content, string $type = Response::TYPE_HTML, ?string $content_type = null) {
+               DI::apiResponse()->setType($type, $content_type);
                DI::apiResponse()->addContent($content);
                DI::page()->exit(DI::apiResponse()->generate());
 
@@ -435,6 +435,40 @@ class System
                return max($load_arr[0], $load_arr[1]);
        }
 
+       /**
+        * Fetch the load and number of processes
+        *
+        * @return array
+        */
+       public static function getLoadAvg(): array
+       {
+               $content = @file_get_contents('/proc/loadavg');
+               if (empty($content)) {
+                       $content = shell_exec('cat /proc/loadavg');
+               }
+               if (empty($content) || !preg_match("#([.\d]+)\s([.\d]+)\s([.\d]+)\s(\d+)/(\d+)#", $content, $matches)) {
+                       $load_arr = sys_getloadavg();
+                       if (empty($load_arr)) {
+                               return [];
+                       }
+                       return [
+                               'average1'  => $load_arr[0],
+                               'average5'  => $load_arr[1],
+                               'average15' => $load_arr[2],
+                               'runnable'  => 0,
+                               'scheduled' => 0
+                       ];
+               }
+
+               return [
+                       'average1'  => (float)$matches[1],
+                       'average5'  => (float)$matches[2],
+                       'average15' => (float)$matches[3],
+                       'runnable'  => (float)$matches[4],
+                       'scheduled' => (float)$matches[5]
+               ];
+       }
+
        /**
         * Redirects to an external URL (fully qualified URL)
         * If you want to route relative to the current Friendica base, use App->internalRedirect()