简体   繁体   中英

Amazon S3 StreamWrapper fread Issue In PHP

I am using amazon s3 API and setting the client to read as stream. It is working fine for me to use file_get_contents("s3://{bucket}/{key}"), which read the full data for the file(I am using video file & testing on my local system). However, I am trying to optimize the memory used by the script and thus trying to read and return data by chunk as below:

$stream = @fopen("s3://{bucket}/{key}", 'r');
$buffer = 1024;
while(!feof($stream)) {
            echo  @fread($stream, $buffer);
            flush();
        }

This is not working on my local system. I am just wondering what might be the issue using this technique. by searching, I found that this is also a very widely used technique. So, if anybody can please give any suggestion about what might be wrong here or any other approach, I should try with, it will be very helpful. Thanks.

OK, finally got the solution. Somehow, some other output are being added to buffer. I had to put:

ob_get_clean();
header('Content-Type: video/quicktime');

In this way to clean anything if were added. Now its working fine.

Thanks Mark Baker for your valuable support through the debugging process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM