Very long exexution time - PDF Extract API
Hi All
I am new to the PDF Extract API and today I have set up mye first php script to convert pdf files. The API returns neccesarry assetID, documentURI and jobID without any errors in any of the cURL requests. I get all 200 and 201 status-codes, which I'm supposed to. However, the json result/file is never returned by the script. I have created a loop/sleep functionality to monitor the status of the project. The status of the extract-job is written to a .log file like below. The job has been running for two hours now and I guess that's not normal. Have anyone had the same experience as described? If anyone could point me in the right direction it would be great.
Here is the code used to check the status of the job:
while(!$jobCompleted) {
// Step 4: Poll the job status
$ch4 = curl_init($jobStatusUrl);
curl_setopt($ch4, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch4, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $accessToken,
'x-api-key: ' . $apiKey
));
$response4 = curl_exec($ch4);
$info4 = curl_getinfo($ch4);
$logMessage = date('Y-m-d H:i:s') . " - Checking job status... "; // Prepare log message
if(curl_errno($ch4)) {
$logMessage .= 'Curl error (Step 4): ' . curl_error($ch4) . "\n";
file_put_contents($logFile, $logMessage, FILE_APPEND); // Log the message
break;
} else {
// Check HTTP status code
if ($info4['http_code'] == 200) {
// Parse the response
$responseData4 = json_decode($response4, true);
// Check if job is completed
if (isset($responseData4['status']) && $responseData4['status'] == 'SUCCEEDED') {
$jobCompleted = true;
$downloadUrl = $responseData4['output']['href']; // The API should provide the download URL in the response when the job is succeeded.
$logMessage .= "Job completed. Download URL: " . $downloadUrl . "\n";
file_put_contents($logFile, $logMessage, FILE_APPEND); // Log the message
break;
} else {
$logMessage .= "Job is still processing...\n";
file_put_contents($logFile, $logMessage, FILE_APPEND); // Log the message
}
} else {
$logMessage .= "Failed to get the job status. HTTP Code: " . $info4['http_code'] . "\n";
file_put_contents($logFile, $logMessage, FILE_APPEND); // Log the message
break;
}
}
curl_close($ch4);
// If job not completed, wait for a while before retrying
if (!$jobCompleted) {
sleep($retryAfterSeconds);
}
}