Skip to content
Snippets Groups Projects
Commit 352827e0 authored by root's avatar root
Browse files

Optimizing memory use - fix #3

parent 46b88a41
No related branches found
No related tags found
1 merge request!8Prod
<?php
namespace SmartData;
require_once('../bin/smartdata/SmartAPI.php');
use function SmartData\SmartAPI\describe;
use SmartData\Exception\CustomException;
use SmartData\Logger;
http_response_code(HttpStatusCode::BAD_REQUEST);
try {
$content = file_get_contents('php://input');
$response = describe($content);
}catch(CustomException $e){
http_response_code($e->getHTTPCodeError());
Logger::exception($e);
return false;
}catch(\Exception $e){
http_response_code(HttpStatusCode::BAD_REQUEST);
Logger::exception($e);
return false;
}
http_response_code(HttpStatusCode::NO_CONTENT);
echo $response;
<?php
namespace SmartData;
require_once('../bin/smartdata/SmartAPI.php');
use function SmartData\SmartAPI\finish;
use SmartData\Exception\CustomException;
use SmartData\Logger;
http_response_code(HttpStatusCode::BAD_REQUEST);
try {
$content = file_get_contents('php://input');
$response = finish($content);
}catch(CustomException $e){
http_response_code($e->getHTTPCodeError());
header('X-Message: '. $e->getMessage(), false);
return false;
}catch(\Exception $e){
http_response_code(HttpStatusCode::BAD_REQUEST);
return false;
}
http_response_code(HttpStatusCode::NO_CONTENT);
echo $response;
<?php
namespace SmartData;
require_once('../bin/smartdata/SmartAPI.php');
use function SmartData\SmartAPI\list_devices;
use SmartData\Exception\CustomException;
use SmartData\Logger;
http_response_code(HttpStatusCode::BAD_REQUEST);
try {
$content = file_get_contents('php://input');
$response = list_devices($content);
}catch(CustomException $e){
http_response_code($e->getHTTPCodeError());
Logger::exception($e);
return false;
}catch(\Exception $e){
http_response_code(HttpStatusCode::BAD_REQUEST);
Logger::exception($e);
return false;
}
http_response_code(HttpStatusCode::OK);
echo $response;
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function doLogin() {
console.log("iniciando...");
let xhr = new XMLHttpRequest();
xhr.open("POST", "https://iot.lisha.ufsc.br/grafana/login");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onload = () => { document.getElementById("grafana_frame").src = "https://iot.lisha.ufsc.br:3000/"; }
let data = '{ "user": "aqtech@lisha.ufsc.br", "password": "jP#55Mh@" } ';
xhr.send(data);
console.log('Enviou...');
}
</script>
</head>
<body onload="doLogin();">
<iframe src="" style="min-width:800px; min-height:900px;" id="grafana_frame" name="grafana_frame"></iframe>
</iframe>
</body>
</html>
<?php
namespace SmartData;
require_once('../bin/smartdata/SmartAPI.php');
require_once('../bin/smartdata/Logger.php');
require_once('../bin/smartdata/SmartData.php');
require_once('../bin/smartdata/MultiSmartData.php');
use SmartData\Exception\{AuthenticationException,BadRequestException,InternalException};
http_response_code(HttpStatusCode::BAD_REQUEST);
try {
}catch(Exception\CustomException $e){
http_response_code($e->getHTTPCodeError());
error_log( $e );
header('X-Message: '.$e->getMessage(), false);
return false;
}catch(\Exception $e){
http_response_code(HttpStatusCode::BAD_REQUEST);
error_log( $e );
header('X-Message: '.$e->getMessage(), false);
return false;
}
http_response_code(HttpStatusCode::NO_CONTENT);
......@@ -40,8 +40,7 @@ namespace SmartData\SmartAPI
}
if($return != NULL){
$return = json_encode($return);
$return = preg_replace('/:"([0-9]*)"/',':$1',$return);
$return = json_encode( $return, JSON_NUMERIC_CHECK );
} else {
throw new RequestFailedException("Error processing request: null return");
}
......@@ -94,8 +93,7 @@ namespace SmartData\SmartAPI
}
$pos = $pos + 1;
}
$return = json_encode($return);
$return = preg_replace('/:"([0-9]*)"/',':$1',$return);
$return = json_encode( $return, JSON_NUMERIC_CHECK );
} else {
throw new RequestFailedException("Error processing request: null return");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment