ZF-6477: Zend_Service_Amazon_S3 : Does not work for buckets located in EU

Issue Type: Bug Created: 2009-04-30T00:47:42.000+0000 Last Updated: 2009-06-29T06:10:31.000+0000 Status: Resolved Fix version(s): - 1.8.2 (27/May/09)

Reporter: Ivo Meißner (zendjunky) Assignee: Jon Whitcraft (sidhighwind) Tags: - Zend_Service_Amazon

Related issues: Attachments: - S3.php


When you try to put an object into a bucket located in EU, you get an error from amazon, that this bucket must be accessed using the specific endpoint ( I have changed the function _makeRequest as follows. It seems to work so far with these changes. Haven't tested intensively.

<pre class="highlight">
     * Make a request to Amazon S3
     * TODO: support style
     * @param  string $method
     * @param  string $path
     * @param  array  $params
     * @param  array  $headers
     * @param  string $data
     * @return Zend_Http_Response
    public function _makeRequest($method, $path='', $params=null, $headers=array(), $data=null)
        $retry_count = 0;

        if (!is_array($headers)) {
            $headers = array($headers);

        $headers['Date'] = gmdate(DATE_RFC1123, time());

        $parts = explode('/', $path);
        self::addSignature($method, $path, $headers);

        $client = self::getHttpClient();

        // Work around buglet in HTTP client - it doesn't clean headers
        // Remove when ZHC is fixed
        $client->setHeaders(array('Content-MD5' => null, 'Expect' => null, 'Range' => null));
        $endpoint = self::S3_ENDPOINT;
        if (count($parts) > 1){
            $endpoint = str_replace('http://', 'http://' . $parts[0] . '.', $endpoint);
            $client->setUri($endpoint.'/'.implode('/', $parts));
        } else {

        if (is_array($params)) {
            foreach ($params as $name=>$value) {
                $client->setParameterGet($name, $value);

         if (($method == 'PUT') && ($data !== null)) {
             if (!isset($headers['Content-type'])) {
                 $headers['Content-type'] = self::getMimeType($path);
             $client->setRawData($data, $headers['Content-type']);

         do {
            $retry = false;

            $response = $client->request($method);
            $response_code = $response->getStatus();

            // Some 5xx errors are expected, so retry automatically
            if ($response_code >= 500 && $response_code < 600 && $retry_count <= 5) {
                $retry = true;
                sleep($retry_count / 4 * $retry_count);
            else if ($response_code == 307) {
                // Need to redirect, new S3 endpoint given
                // This should never happen as Zend_Http_Client will redirect automatically
            else if ($response_code == 100) {
                //echo 'OK to Continue';
        } while ($retry);
        return $response;


Posted by Matthew Weier O'Phinney (matthew) on 2009-04-30T05:09:53.000+0000

Assigning to Jon

Posted by Jon Whitcraft (sidhighwind) on 2009-04-30T06:51:20.000+0000

Could your attach a patch file so i apply this and test it?


Posted by Ivo Meißner (zendjunky) on 2009-05-04T02:27:01.000+0000

Here is a patchfile with the changes.

Posted by Kristof Coomans (cyberwolf) on 2009-05-18T07:51:55.000+0000

IMHO it would be a good idea to handle Amazon S3 API permanent redirects, which seem to use the HTTP status 301 and do not set a location header (and are therefore not handled by Zend_HTTP_Client).

Posted by Jon Whitcraft (sidhighwind) on 2009-05-19T12:35:15.000+0000


I didn't write this component to i'm not too entierly sure what you are talking about. Can you please provide the docs page that explains that or submit a patch?

Posted by Kristof Coomans (cyberwolf) on 2009-05-19T12:45:26.000+0000

Hi Jon

You can find more information about it at…, under "Permanent Request Redirection". After thinking a bit more about this, it might be better to use domain-style requests after all, as Ivo suggests. That works in all cases (EU and US-located buckets).

Posted by Jon Whitcraft (sidhighwind) on 2009-05-20T08:43:42.000+0000

This has been resolved and checked-in to svn.

Posted by Peter Ritter (pinopinelli) on 2009-06-29T06:10:29.000+0000


are you shure that is suitable for all operations that can be done? When I try to DELETE an object from a bucket (in the EU) then I get an positive response from S3. But my object is still there. I guess the problem is, that Amazon's API also returns this positive response when you try to delete an object that does not even exist. I did not test for other operations yet.

Have you found an issue?

See the Overview section for more details.


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

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