stream_read ( $count )

Read from stream. This method is called in response to fread() and fgets().

It is important to avoid reading files that are near to or larger than the amount of memory allocated to PHP, otherwise “out of memory” errors will occur.

Access

public

Parameters

Parameter

Type

Required

Description

$count

integer

Required

Always equal to 8192. PHP is fun, isn’t it?

Returns

Type

Description

string

The contents of the Amazon S3 object.

Source

Method defined in extensions/s3streamwrapper.class.php | Toggle source view (47 lines) | View on GitHub

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

    list($protocol, $bucket, $object_name) = $this->parse_path($this->path);

    if ($this->seek_position > 0 && $this->object_size)
    {
        if ($count + $this->seek_position > $this->object_size)
        {
            $count = $this->object_size - $this->seek_position;
        }

        $start = $this->seek_position;
        $end = $this->seek_position + $count;

        $response = $this->client($protocol)->get_object($bucket, $object_name, array(
            'range' => $start . '-' . $end
        ));
    }
    else
    {
        $response = $this->client($protocol)->get_object($bucket, $object_name);
        $this->object_size = isset($response->header['content-length']) ? $response->header['content-length'] : 0;
    }

    if (!$response->isOK())
    {
        return false;
    }

    $data = substr($response->body, 0, min($count, $this->object_size));
    $this->seek_position += strlen($data);


    if ($this->seek_position >= $this->object_size)
    {
        $this->eof = true;
        $this->seek_position = 0;
        $this->object_size = 0;
    }

    return $data;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback