diff --git a/script.php b/script.php index dce2ca1..98932f8 100644 --- a/script.php +++ b/script.php @@ -104,6 +104,7 @@ $stats = [ foreach ($accessnumbers as $index => $accessnumber) { $current = $index + 1; echo "[$current/$total] $accessnumber... "; + flush(); try { // Check if request exists and get language @@ -144,12 +145,16 @@ foreach ($accessnumbers as $index => $accessnumber) { $data['ispdf'] = 1; // Generate HTML + echo "generating HTML... "; + flush(); $html = view('report/template', $data); $filename = $accessnumber . ($eng == 1 ? '_eng' : '') . '.pdf'; $collectionDate = $data['collectionDate'] ?? ''; $hostnumber = $data['hostnumber'] ?? ''; // Send to PDF spooler + echo "sending to spooler... "; + flush(); $jobId = postToSpooler($html, $filename, $collectionDate, $accessnumber, $hostnumber); // Log to AUDIT_REQUESTS @@ -264,12 +269,18 @@ function postToSpooler(string $html, string $filename, string $collectionDate = curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $curlError = curl_error($ch); curl_close($ch); + if ($curlError) { + throw new \Exception("cURL error: $curlError"); + } + if ($httpCode !== 200) { throw new \Exception("Spooler API returned HTTP $httpCode"); }