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:
我想创建一个.zip归档文件,将其上载到Amazon S3,然后从服务器删除创建的.zip。步骤1和步骤2运行良好,但是删除步骤返回:
unlink(temp/file.zip): Resource temporarily unavailable
分离(temp / file.zip):资源暂时不可用
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.
一些附加细节:我正在使用Lumen 5.4和aws-sdk-php-laravel包。
Any insight would be much appreciated! Thanks.
任何见解都将不胜感激!谢谢。
1 个解决方案
#1
4
S3 is holding resources so we have to forcefully clear the gc (Garbage Collector).
S3持有资源,所以我们必须强力清除gc(垃圾收集器)。
Just do gc_collect_cycles()
before deleting that file.
在删除该文件之前,只需执行gc_collect_loop()。
#1
4
S3 is holding resources so we have to forcefully clear the gc (Garbage Collector).
S3持有资源,所以我们必须强力清除gc(垃圾收集器)。
Just do gc_collect_cycles()
before deleting that file.
在删除该文件之前,只需执行gc_collect_loop()。