3.109.8
php -v)?PHP 7.2.5 (cli) (built: Apr 26 2018 12:05:41) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.5, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
with blackfire v1.22.0~mac-x64-non_zts72, https://blackfire.io, by Blackfire
When opening an s3://... stream in seekable mode, the size (reported by fstat) is always zero.
But non-seekable mode reports the size correctly.
Here's a little script. php {scriptName} s3://someBucketThatExists/someFileThatExists
<?php
use Aws\S3\S3Client;
require __DIR__.'/vendor/autoload.php';
if (!isset($argv[1])) {
fprintf(STDERR, 'Usage: %s s3://bucket/file.txt%s', $argv[0], PHP_EOL);
exit(1);
}
$url = $argv[1];
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-1',
]);
$s3->registerStreamWrapper();
$nonSeekableContext = stream_context_create([
's3' => [
'seekable' => false,
],
]);
$nonSeekable = fopen($url, 'r', false, $nonSeekableContext);
$nonSeekableStat = fstat($nonSeekable);
echo 'Non Seekable', PHP_EOL;
echo '------------', PHP_EOL;
echo $nonSeekableStat['size'], PHP_EOL, PHP_EOL;
$seekableContext = stream_context_create([
's3' => [
'seekable' => true,
],
]);
$seekable = fopen($url, 'r', false, $seekableContext);
$seekableStat = fstat($seekable);
echo 'Seekable', PHP_EOL;
echo '--------', PHP_EOL;
echo $seekableStat['size'], PHP_EOL;
exit($seekableStat['size'] < 1 ? 1 : 0);
See also #590
Seems like something cause by the CachingStream which tries to determine the size of the target vs remote streams -- the temporary, local stream seems to report a size of zero and the remote stream says its size is null.
The stream wrapper favors whatever is available from the response body.
Seems like fstat on any S3 url should always report the size of the remote file?
Hi @chrisguitarguy, thanks for bringing this to our attention and I do apologize for the delay in response on our end. I'm able to reproduce the described behavior and can confirm this is a bug within the AWS SDK for PHP. I have brought this up with the rest of the team to work toward a resolution. Once we have additional information on this we will update the issue accordingly.
@chrisguitarguy We just merged in #1875, which should take care of this issue and will be included in the next release. Thanks for bringing this to our attention!
Thanks y'all!