+ * Returns the current Load of the System
+ *
+ * @return integer
+ */
+ public static function currentLoad()
+ {
+ if (!function_exists('sys_getloadavg')) {
+ return false;
+ }
+
+ $load_arr = sys_getloadavg();
+
+ if (!is_array($load_arr)) {
+ return false;
+ }
+
+ return max($load_arr[0], $load_arr[1]);
+ }
+
+ /**
+ * Redirects to an external URL (fully qualified URL)
+ * If you want to route relative to the current Friendica base, use App->internalRedirect()
+ *
+ * @param string $url The new Location to redirect
+ * @param int $code The redirection code, which is used (Default is 302)
+ *
+ * @throws InternalServerErrorException If the URL is not fully qualified
+ */
+ public static function externalRedirect($url, $code = 302)
+ {
+ if (empty(parse_url($url, PHP_URL_SCHEME))) {
+ throw new InternalServerErrorException("'$url' is not a fully qualified URL, please use App->internalRedirect() instead");
+ }
+
+ switch ($code) {
+ case 302:
+ // this is the default code for a REDIRECT
+ // We don't need a extra header here
+ break;
+ case 301:
+ header('HTTP/1.1 301 Moved Permanently');
+ break;
+ case 307:
+ header('HTTP/1.1 307 Temporary Redirect');
+ break;
+ }
+
+ header("Location: $url");
+ exit();
+ }
+
+ /**
+ * Returns the system user that is executing the script
+ *
+ * This mostly returns something like "www-data".
+ *
+ * @return string system username
+ */
+ public static function getUser()
+ {
+ if (!function_exists('posix_getpwuid') || !function_exists('posix_geteuid')) {
+ return '';
+ }
+
+ $processUser = posix_getpwuid(posix_geteuid());
+ return $processUser['name'];
+ }
+
+ /**
+ * Checks if a given directory is usable for the system
+ *
+ * @param $directory
+ * @param bool $check_writable