Skip to content

Commit

Permalink
Adjustment to loader to decrease the sse event process, many thing ar…
Browse files Browse the repository at this point in the history
…e not necessary so this reduces the time from ~250ms to ~80ms
  • Loading branch information
austinwbest committed May 12, 2024
1 parent bfcd66a commit 879c7b8
Showing 1 changed file with 58 additions and 50 deletions.
108 changes: 58 additions & 50 deletions root/app/www/public/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
// This will NOT report uninitialized variables
error_reporting(E_ERROR | E_PARSE);

//-- ADJUST THIS HERE
//-- USE THIS VARIABLE TO BYPASS THINGS NOT NEEDED FOR THE SSE EVENT, ~250ms to ~80MS
define('IS_SSE', (str_contains($_SERVER['PHP_SELF'], 'sse') && !str_contains($_SERVER['PHP_SELF'], 'cron') ? true : false));

//-- ADJUST THIS HERE, SOCKET PROXY USER
if ($_SERVER['DOCKER_HOST']) {
$_SERVER['DOCKER_HOST'] = str_contains($_SERVER['DOCKER_HOST'], '://') ? $_SERVER['DOCKER_HOST'] : 'http://' . $_SERVER['DOCKER_HOST'];
$_SERVER['DOCKER_HOST'] = str_replace('tcp://', 'http://', $_SERVER['DOCKER_HOST']); //-- libcurl
Expand All @@ -28,8 +31,9 @@
}
}

$loadTimes = [];
$start = microtime(true);
$apiError = '';
$loadTimes = [];
$start = microtime(true);

//-- DIRECTORIES TO LOAD FILES FROM, ORDER IS IMPORTANT
$autoloads = ['includes', 'functions', 'classes'];
Expand All @@ -51,18 +55,22 @@

$loadTimes[] = trackTime('page ->', $start);

//-- INIT THE CLASS
$docker = new Docker();

if (!$_SESSION) {
session_start();
}

automation();
if (!IS_SSE) {
//-- INITIALIZE THE DOCKER CLASS
$docker = new Docker();

$dockerCommunicateAPI = $docker->apiIsAvailable();
//-- RUN REQUIRED CHECKS
automation();

//-- CHECK IF DOCKER IS AVAILABLE
$dockerCommunicateAPI = $docker->apiIsAvailable();
}

//-- SERVERS
//-- GET THE SERVERS LIST
$serversFile = getFile(SERVERS_FILE);
$_SESSION['serverIndex'] = is_numeric($_SESSION['serverIndex']) ? $_SESSION['serverIndex'] : 0;

Expand All @@ -71,42 +79,40 @@
define('ACTIVE_SERVER_APIKEY', $serversFile[$_SESSION['serverIndex']]['apikey']);

if (!str_contains_any($_SERVER['PHP_SELF'], ['/api/']) && !str_contains($_SERVER['PWD'], 'oneshot')) {
//-- CHECK IF SELECTED SERVER CAN BE TALKED TO
$ping = apiRequest('ping');
if (!is_array($ping) || $ping['code'] != 200) {
if ($_SESSION['serverIndex'] == 0) {
exit('The connection to this container in the servers file is broken');
} else {
$_SESSION['serverIndex'] = 0;
header('Location: /');
exit();
if (!IS_SSE) {
//-- CHECK IF SELECTED SERVER CAN BE TALKED TO
$ping = apiRequest('ping');
if (!is_array($ping) || $ping['code'] != 200) {
if ($_SESSION['serverIndex'] == 0) {
exit('The connection to this container in the servers file is broken');
} else {
$_SESSION['serverIndex'] = 0;
header('Location: /');
exit();
}
}
}

//-- SETTINGS
$settingsFile = getServerFile('settings');
if ($settingsFile['code'] != 200) {
$apiError = $settingsFile['file'];
}
$settingsFile = $settingsFile['file'];
$settingsFile = getServerFile('settings');
$apiError = $settingsFile['code'] != 200 ? $settingsFile['file'] : $apiError;
$settingsFile = $settingsFile['file'];

//-- LOGIN, DEFINE AFTER LOADING SETTINGS
define('LOGIN_FAILURE_LIMIT', ($settingsFile['global']['loginFailures'] ? $settingsFile['global']['loginFailures']: 10));
define('LOGIN_FAILURE_TIMEOUT', ($settingsFile['global']['loginFailures'] ? $settingsFile['global']['loginTimeout']: 10)); //-- MINUTES TO DISABLE LOGINS

//-- STATE
$stateFile = getServerFile('state');
if ($stateFile['code'] != 200) {
$apiError = $stateFile['file'];
}
$stateFile = $stateFile['file'];
if (!IS_SSE) {
//-- STATE
$stateFile = getServerFile('state');
$apiError = $stateFile['code'] != 200 ? $stateFile['file'] : $apiError;
$stateFile = $stateFile['file'];

//-- PULLS
$pullsFile = getServerFile('pull');
if ($pullsFile['code'] != 200) {
$apiError = $pullsFile['file'];
//-- PULLS
$pullsFile = getServerFile('pull');
$apiError = $pullsFile['code'] != 200 ? $pullsFile['file'] : $apiError;
$pullsFile = $pullsFile['file'];
}
$pullsFile = $pullsFile['file'];

if (file_exists(LOGIN_FILE) && !str_contains($_SERVER['PHP_SELF'], '/crons/')) {
define('USE_AUTH', true);
Expand Down Expand Up @@ -135,22 +141,24 @@
}
}

$fetchProc = in_array($_POST['page'], $getProc) || $_POST['hash'];
$fetchStats = in_array($_POST['page'], $getStats) || $_POST['hash'];
$fetchInspect = in_array($_POST['page'], $getInspect) || $_POST['hash'];
if (!IS_SSE) {
$fetchProc = in_array($_POST['page'], $getProc) || $_POST['hash'];
$fetchStats = in_array($_POST['page'], $getStats) || $_POST['hash'];
$fetchInspect = in_array($_POST['page'], $getInspect) || $_POST['hash'];

$loadTimes[] = trackTime('getExpandedProcessList ->');
$getExpandedProcessList = getExpandedProcessList($fetchProc, $fetchStats, $fetchInspect);
$processList = $getExpandedProcessList['processList'];
foreach ($getExpandedProcessList['loadTimes'] as $loadTime) {
$loadTimes[] = $loadTime;
}
$loadTimes[] = trackTime('getExpandedProcessList <-');
$loadTimes[] = trackTime('getExpandedProcessList ->');
$getExpandedProcessList = getExpandedProcessList($fetchProc, $fetchStats, $fetchInspect);
$processList = $getExpandedProcessList['processList'];
foreach ($getExpandedProcessList['loadTimes'] as $loadTime) {
$loadTimes[] = $loadTime;
}
$loadTimes[] = trackTime('getExpandedProcessList <-');

//-- UPDATE THE STATE FILE WHEN EVERYTHING IS FETCHED
if ($_POST['page'] == 'overview' || $_POST['page'] == 'containers') {
setServerFile('state', json_encode($processList));
}
//-- UPDATE THE STATE FILE WHEN EVERYTHING IS FETCHED
if ($_POST['page'] == 'overview' || $_POST['page'] == 'containers') {
setServerFile('state', json_encode($processList));
}

//-- STATE
$stateFile = $processList;
//-- STATE
$stateFile = $processList;
}

0 comments on commit 879c7b8

Please sign in to comment.