I'm attempting to upload many images to an S3 bucket. With speed in mind, I'm looking to reduce the number of disk reads and writes by keeping the data in memory. To this end, I have come up with the following scheme:
//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);
The error is: S3::putObject(): [RequestTimeout] Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed and data is not written to S3.
If I replace the assignment of $out to simply an empty string: $out = "";
Then, the library successfully writes 0 byte files to S3 as expected.
I'm using CodeIgniter S3 library... which is just a wrapper around AWS S3 API afaik.