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) {
|
||||
$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");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user