我试图上传很多图像到S3存储桶。考虑到速度,我希望通过将数据保存在内存中来减少磁盘读取和写入的次数。为此,我想出了以下方案:传递二进制数据到S3 PutObject
//fetch binary image data from remote URL
$contents = file_get_contents("http://somesite.com/image.jpg");
//trim the image as per: http://stackoverflow.com/a/15104071/568884
$out = shell_exec('echo ' . base64_encode($contents) . " | base64 -d | convert - -fuzz 10% -trim jpeg:-");
//create a temporary resource to pass to S3's inputResource() method.
$resource = fopen('php://temp', 'r+');
//write the binary data into the empty resource.
fwrite($resource, $out);
//pass the resource and length of binary data into inputResource()
$ir = $this->s3->inputResource($resource, strlen($out));
//finally transfer the resource from machine to S3.
$this->s3->putObject($ir, $bucket, $s3_path, S3::ACL_PUBLIC_READ);
的错误是:S3 :: putObject():将requestTimeout]你的套接字连接到服务器是无法读取或内写入超时期限。空闲连接将被关闭并且数据不会写入S3。
如果我将$ out的赋值替换为简单的空字符串:$out = "";
然后,库按预期方式成功地将0字节文件写入S3。
我正在使用CodeIgniter S3库...这只是AWS S3 API afaik的一个包装。
PHP是不是真的这个东西的最佳选择。一个更好的设计会使用诸如Python,Java或Ruby之类的批处理工作排队。您可以轻松地从您的PHP应用程序创建工作,并让工作人员处理繁重的工作。 – jamieb 2013-03-04 02:06:35
你使用s3 SDK还是第三方课程? – 2013-03-09 00:27:00
按照问题“我正在使用CodeIgniter S3库,它只是AWS S3 API afaik的包装器。” – 2013-03-09 02:25:20