Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would cause unlink to return 'Resource Temporarily Unavailable'?

I'd like to create a .zip archive, upload it to Amazon S3, then delete the created .zip from the server. Steps 1 and 2 are working great, but the delete step is returning:

unlink(temp/file.zip): Resource temporarily unavailable

I've tried to unset all the related variables and resources, but I'm still getting the error.

Here's the code:

$zipFile = 'temp/file.zip';

// create the zip archive:
$z = new \ZipArchive();
$z->open($zipFile, \ZipArchive::CREATE);
$z->addEmptyDir('testdirectory');

// add a file
$filename = 'fileName.txt';
$content = 'Hello World';
$z->addFromString('testdirectory/' . $filename, $content);
$z->close();

// upload to S3
$s3 = AWS::createClient('s3');
$result = $s3->putObject(array(
    'Bucket'        =>  'my-bucket-name',
    'Key'           =>  basename($zipFile),
    'SourceFile'    =>  $zipFile
));

// check to see if the file was uploaded
if ($result['@metadata']['statusCode'] == "200") {
    $uploaded = true;
}

// delete the temp file
if ($uploaded) {
    unset($result);
    unset($s3);
    unset($z);
    if (file_exists($zipFile)) {
        unlink($zipFile);
    }
}

Some additional details: I'm using Lumen 5.4 and the aws-sdk-php-laravel package.

Any insight would be much appreciated! Thanks.

like image 846
WayneC Avatar asked Dec 05 '25 09:12

WayneC


1 Answers

S3 is holding resources so we have to forcefully clear the gc (Garbage Collector).

Just do gc_collect_cycles() before deleting that file.

like image 131
Mohammed Sufyan Shaikh Avatar answered Dec 07 '25 23:12

Mohammed Sufyan Shaikh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!