Laravel Jobs: File created in job won't delete till queue has stopped

25 Views Asked by At

I am creating a temporary file in a Laravel Job which I want to delete later in the same job. However, the file does not seem to delete until the entire queue worker has been stopped. The file is created as follows:

$zip = new ZipArchive;
$zipPath = $job->output_file_location.'screenshot.zip';
$zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addFile($outputFileLocation, 'screenshot.png');
$zip->close();

Later the file is deleted using unlink($zipPath);. However, the file does not seem to delete until I stop the entire queue worker. The application is build using Laravel version 10.2.0 in combination with PHP 8.2.0 and running on a Windows 10 machine (XAMPP).

I have tried moving the deletion of the file to a different job which is delayed by 5 seconds. This did not resolve the issue. I can not delete the file using Windows File Explorer either as long as the queue worker is running.

Does anybody have an idea what might be causing the issue and how to resolve it?

0

There are 0 best solutions below