PHP:如何在不使用CLI的情况下使用php代码在s3存储桶之间同步数据? [英] PHP: How to sync data between s3 buckets using php code without using the CLI .?

查看:77
本文介绍了PHP:如何在不使用CLI的情况下使用php代码在s3存储桶之间同步数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在amazon-s3的php sdk中找不到同步和复制选项。目前,我正在PHP代码中使用aws s3 cp / sync CLI命令来实现此目标,这对我来说似乎并不那么整洁。有任何想法吗?

I can't seem to find sync and copy options in the php sdk for amazon-s3. Currently I am using aws s3 cp/sync CLI command from within PHP code to achieve this which doesn't seem very neat to me. Any ideas?

推荐答案

您可以结合使用PHP SDK中的两个功能。

You can do this with a combination of two features in the PHP SDK.

首先,签出 S3Client :: uploadDirectory()方法(请参见用户指南)。您可以像这样上传一会儿目录的内容:

First, checkout the S3Client::uploadDirectory() method (see user guide). You can upload a while directory's contents like this:

$s3Client->uploadDirectory('/local/directory', 'your-bucket-name');

如果将其与 S3 Stream Wrapper ,然后您可以指定使用本地目录作为源

If you combine this with the S3 Stream Wrapper, then instead of using a local directory as the source, you can specify a bucket.

$s3Client->registerStreamWrapper();
$s3Client->uploadDirectory('s3://your-other-bucket-name', 'your-bucket-name');

此功能非常强大,因为如果使用不同配置的<$,甚至可以跨区域执行某些操作与执行 uploadDirectory()的对象相比,Stream Wrapper的c $ c> S3Client 对象。

This is pretty powerful, because you can even do something across regions if you use a differently configured S3Client object for the Stream Wrapper than the one doing the uploadDirectory().

这篇关于PHP:如何在不使用CLI的情况下使用php代码在s3存储桶之间同步数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆