fixed warm cache
This commit is contained in:
@@ -55,6 +55,7 @@ class VisualLimsApiClient
|
|||||||
]);
|
]);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
$this->applyTimeouts($ch);
|
||||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||||
$log = fopen(__DIR__ . '/curl_auth_debug.log', 'a') ?: fopen('php://stderr', 'w');
|
$log = fopen(__DIR__ . '/curl_auth_debug.log', 'a') ?: fopen('php://stderr', 'w');
|
||||||
curl_setopt($ch, CURLOPT_STDERR, $log);
|
curl_setopt($ch, CURLOPT_STDERR, $log);
|
||||||
@@ -91,6 +92,19 @@ class VisualLimsApiClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timeout di rete: evita che una richiesta resti appesa all'infinito
|
||||||
|
* se il gestionale smette di rispondere (connessione "morta").
|
||||||
|
* $idleSeconds = secondi senza trasferire dati prima di abbandonare.
|
||||||
|
*/
|
||||||
|
private function applyTimeouts($ch, $idleSeconds = 120)
|
||||||
|
{
|
||||||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
||||||
|
curl_setopt($ch, CURLOPT_TCP_KEEPALIVE, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, $idleSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
private function getToken()
|
private function getToken()
|
||||||
{
|
{
|
||||||
if ($this->token === null) {
|
if ($this->token === null) {
|
||||||
@@ -113,6 +127,7 @@ class VisualLimsApiClient
|
|||||||
]);
|
]);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
$this->applyTimeouts($ch);
|
||||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||||
$log = fopen(__DIR__ . '/curl_request_debug.log', 'w') ?: fopen('php://stderr', 'w');
|
$log = fopen(__DIR__ . '/curl_request_debug.log', 'w') ?: fopen('php://stderr', 'w');
|
||||||
curl_setopt($ch, CURLOPT_STDERR, $log);
|
curl_setopt($ch, CURLOPT_STDERR, $log);
|
||||||
@@ -156,6 +171,7 @@ class VisualLimsApiClient
|
|||||||
]);
|
]);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
$this->applyTimeouts($ch, 300);
|
||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
@@ -190,6 +206,7 @@ class VisualLimsApiClient
|
|||||||
]);
|
]);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
$this->applyTimeouts($ch, 300);
|
||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
@@ -239,8 +256,9 @@ class VisualLimsApiClient
|
|||||||
]);
|
]);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
$this->applyTimeouts($ch, 300);
|
||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
$curl_error = curl_error($ch);
|
$curl_error = curl_error($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
@@ -280,6 +298,7 @@ class VisualLimsApiClient
|
|||||||
]);
|
]);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
$this->applyTimeouts($ch, 300);
|
||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ if (!$isCli) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Libera subito la sessione: il warm dura minuti e altrimenti blocca
|
||||||
|
// tutte le altre pagine dello stesso utente fino alla fine.
|
||||||
|
session_write_close();
|
||||||
|
|
||||||
if ($isStream) {
|
if ($isStream) {
|
||||||
// Streaming mode: send progress line-by-line (Server-Sent Events)
|
// Streaming mode: send progress line-by-line (Server-Sent Events)
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
@@ -160,6 +164,7 @@ try {
|
|||||||
$matriceIds = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
$matriceIds = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||||
warmLog("[analisi] Fetching for " . count($matriceIds) . " matrici in use...", $isCli);
|
warmLog("[analisi] Fetching for " . count($matriceIds) . " matrici in use...", $isCli);
|
||||||
|
|
||||||
|
$consecutiveErrors = 0;
|
||||||
foreach ($matriceIds as $mid) {
|
foreach ($matriceIds as $mid) {
|
||||||
$mid = (int)$mid;
|
$mid = (int)$mid;
|
||||||
// Same query as get_analisi_matrice_filter.php with web_only=1 (what the analysis modal requests)
|
// Same query as get_analisi_matrice_filter.php with web_only=1 (what the analysis modal requests)
|
||||||
@@ -169,8 +174,13 @@ try {
|
|||||||
$values = $data['value'] ?? [];
|
$values = $data['value'] ?? [];
|
||||||
file_put_contents($cacheDir . '/analisi_matrice_' . $mid . '.json', json_encode(['value' => $values]));
|
file_put_contents($cacheDir . '/analisi_matrice_' . $mid . '.json', json_encode(['value' => $values]));
|
||||||
warmLog("[analisi] Matrice $mid: " . count($values) . " analisi", $isCli);
|
warmLog("[analisi] Matrice $mid: " . count($values) . " analisi", $isCli);
|
||||||
|
$consecutiveErrors = 0;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
warmLog("[analisi] Matrice $mid: ERROR " . $e->getMessage(), $isCli);
|
warmLog("[analisi] Matrice $mid: ERROR " . $e->getMessage(), $isCli);
|
||||||
|
if (++$consecutiveErrors >= 5) {
|
||||||
|
warmLog("[analisi] ERRORE: gestionale non raggiungibile (5 errori consecutivi), interrompo le analisi.", $isCli);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // fine if includeAnalisi
|
} // fine if includeAnalisi
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ include('include/headscript.php');
|
|||||||
<i class="bx bx-play-circle me-1"></i> Avvia aggiornamento
|
<i class="bx bx-play-circle me-1"></i> Avvia aggiornamento
|
||||||
</button>
|
</button>
|
||||||
<div class="small text-muted mt-2" id="idleHint">
|
<div class="small text-muted mt-2" id="idleHint">
|
||||||
L'operazione può richiedere da qualche secondo a un paio di minuti.
|
Senza analisi richiede circa un minuto, con le analisi fino a 30 minuti. Puoi lasciare questa pagina aperta e continuare a lavorare in un'altra scheda.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Progress -->
|
<!-- Progress -->
|
||||||
|
|||||||
Reference in New Issue
Block a user