Issues

ZF-10035: S3_Stream implementation broken

Issue Type: Bug Created: 2010-06-22T16:05:18.000+0000 Last Updated: 2010-07-17T17:50:07.000+0000 Status: Resolved Fix version(s): - 1.10.7 (28/Jul/10)

Reporter: Florian Hoenig (flo) Assignee: Torio Farazdagi (torio) Tags: - Zend_Service_Amazon

Related issues: Attachments:

Description

fread from a s3 stream always downloads the whole file. This is due to outdated API implementation. Check here for the latest:

http://docs.amazonwebservices.com/AmazonS3/latest/…

Here is the new stream_read function which resolve the 1) wrong range header and 2) wrong check for 200 http code:

public function stream_read($count) { if (!$this->_objectName) { return false; }

    $range_start = $this->_position;
    $range_end = $this->_position+$count;

    // Only fetch more data from S3 if we haven't fetched any data yet (postion=0)
    // OR, the range end position is greater than the size of the current object
    // buffer AND if the range end position is less than or equal to the object's
    // size returned by S3
    if (($this->_position == 0) || (($range_end > strlen($this->_objectBuffer)) && ($range_end <= $this->_objectSize))) {

        $headers = "Range:bytes=$range_start-$range_end";

        $response = $this->_s3->_makeRequest('GET', $this->_objectName, null, $headers);
        $status = (string)$response->getStatus();
        if (strpos($status, "20") === 0) {
            $this->_objectBuffer .= $response->getBody();
        }
    }

    $data = substr($this->_objectBuffer, $this->_position, $count);
    $this->_position += strlen($data);
    return $data;
}

Comments

Posted by Torio Farazdagi (torio) on 2010-07-17T17:50:04.000+0000

Due to http://bugs.php.net/21641 stream_read() always gets 8292 bytes as count, so although on client side (fread) everything works fine, actual stream read step is fixed. But within this step, partial data is requested and returned by Amazon as expected.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts