fix: add progress output and better timeout handling for batch PDF script
- Add flush() after each echo to show progress in real-time - Increase curl timeout to 30 seconds with 10 second connect timeout - Add curl error handling to diagnose connection issues - Add progress messages (generating HTML, sending to spooler)
This commit is contained in:
parent
f35d6647c5
commit
0b569c58d9
13
script.php
13
script.php
@ -104,6 +104,7 @@ $stats = [
|
|||||||
foreach ($accessnumbers as $index => $accessnumber) {
|
foreach ($accessnumbers as $index => $accessnumber) {
|
||||||
$current = $index + 1;
|
$current = $index + 1;
|
||||||
echo "[$current/$total] $accessnumber... ";
|
echo "[$current/$total] $accessnumber... ";
|
||||||
|
flush();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if request exists and get language
|
// Check if request exists and get language
|
||||||
@ -144,12 +145,16 @@ foreach ($accessnumbers as $index => $accessnumber) {
|
|||||||
$data['ispdf'] = 1;
|
$data['ispdf'] = 1;
|
||||||
|
|
||||||
// Generate HTML
|
// Generate HTML
|
||||||
|
echo "generating HTML... ";
|
||||||
|
flush();
|
||||||
$html = view('report/template', $data);
|
$html = view('report/template', $data);
|
||||||
$filename = $accessnumber . ($eng == 1 ? '_eng' : '') . '.pdf';
|
$filename = $accessnumber . ($eng == 1 ? '_eng' : '') . '.pdf';
|
||||||
$collectionDate = $data['collectionDate'] ?? '';
|
$collectionDate = $data['collectionDate'] ?? '';
|
||||||
$hostnumber = $data['hostnumber'] ?? '';
|
$hostnumber = $data['hostnumber'] ?? '';
|
||||||
|
|
||||||
// Send to PDF spooler
|
// Send to PDF spooler
|
||||||
|
echo "sending to spooler... ";
|
||||||
|
flush();
|
||||||
$jobId = postToSpooler($html, $filename, $collectionDate, $accessnumber, $hostnumber);
|
$jobId = postToSpooler($html, $filename, $collectionDate, $accessnumber, $hostnumber);
|
||||||
|
|
||||||
// Log to AUDIT_REQUESTS
|
// Log to AUDIT_REQUESTS
|
||||||
@ -264,12 +269,18 @@ function postToSpooler(string $html, string $filename, string $collectionDate =
|
|||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
'Content-Type: application/json'
|
'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);
|
$response = curl_exec($ch);
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$curlError = curl_error($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($curlError) {
|
||||||
|
throw new \Exception("cURL error: $curlError");
|
||||||
|
}
|
||||||
|
|
||||||
if ($httpCode !== 200) {
|
if ($httpCode !== 200) {
|
||||||
throw new \Exception("Spooler API returned HTTP $httpCode");
|
throw new \Exception("Spooler API returned HTTP $httpCode");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user