The warning:
Warning: unlink(temp/1.pdf): Resource temporarily unavailable in C:\www\test.php on line 122
Warning: unlink(temp/2.pdf): Resource temporarily unavailable in C:\www\test.php on line 123
I'm using PHP's exec
to run a batch file to perform some OCR, so the file cannot be deleted at the time the code is running, as CMD is busy creating the files. Once the files are created, I then use FPDF/FPDI to merge both PDFs, creating a new file in a different directory (merged/file.pdf)
So, what I need to do is wait for the batch file to finish executing, and for CMD to release the files so they can be deleted.
I just don't know how to do this.
$scriptName = 'wscript "launchquiet.vbs" "C:\www\OCR.bat"';
exec($scriptName,$out);
foreach($out as $key => $value) {echo $key." ".$value."<br>";}
That does not work, even though I should be forcing PHP to wait for the script's output by forcing it to wait for the script to finish.
I've also tried
exec('wscript "launchquiet.vbs" "C:\www\OCR.bat" &');
And
exec('wscript "launchquiet.vbs" "C:\www\OCR.bat" 2>&1 &');
With the &
and 2>&1 &
, which should (from Googling) force PHP to wait for the script to finish, but it doesn't.
So, my question namely becomes: is there a way to do this, forcing PHP to wait until the exec finishes; or, how do I make PHP wait, say, 10 seconds, upon deletion failure to try it again (and then wait again if there's another failure)
Edit: the code that does the deleting: unlink("temp/1.pdf");
and unlink("temp/2.pdf");
Edit 2: The whole code
exec('wscript "launchquiet.vbs" "C:\www\OCR.bat"');
PDF::Merge("temp/" . $newFileName . ".png", "temp/" . $newFileName . "_1.pdf", "temp/" . $newFileName . "_2.pdf", $newFileName);
unlink("OCR.bat"); // Delete Files
unlink("temp/" . $newFileName . ".png");
unlink("temp/" . $newFileName . "_1.pdf";
unlink("temp/" . $newFileName . "_2.pdf";