简体   繁体   中英

Amazon Web Service S3 shows SSL cURL error

I'm trying to test in PHP Amazon S3 on my localhost on Ubuntu system but keep getting the same error:

S3::listBuckets(): [35] error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

It is the function to display bucket list.

    public function buckets() {
            $s3 = $this->getInstance();
/*print_r($this->_s3->listBuckets()); nothing is print else shows error */
            return $this->_s3->listBuckets();


        }

Here is the Amazon API function that has been called by this function.

 public static function listBuckets($detailed = false) {
        $rest = new S3Request('GET', '', '');
        $rest = $rest->getResponse();
        if ($rest->error === false && $rest->code !== 200)
            $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
        if ($rest->error !== false) {
            trigger_error(sprintf("S3::listBuckets(): [%s] %s", $rest->error['code'], $rest->error['message']), E_USER_WARNING);
            return false;
        }
        $results = array();
        if (!isset($rest->body->Buckets))
            return $results;

        if ($detailed) {
            if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName))
                $results['owner'] = array(
                    'id' => (string) $rest->body->Owner->ID, 'name' => (string) $rest->body->Owner->ID
                );
            $results['buckets'] = array();
            foreach ($rest->body->Buckets->Bucket as $b)
                $results['buckets'][] = array(
                    'name' => (string) $b->Name, 'time' => strtotime((string) $b->CreationDate)
                );
        }
        else
            foreach ($rest->body->Buckets->Bucket as $b)
                $results[] = (string) $b->Name;

        return $results;
    }

It seems that you have changed your PHP version as this bug is occurred several time in PHP 5.4 but it works perfectly in previous versions. You can re-install cURL with Open SSL again.

It is most common error occurred in integration of AWS S3 on localhost.

  1. Check is cURL is enable and Open SSL is also active.
  2. Get file from http://curl.haxx.se/ca/cacert.pem and save it to your libraries at hard drive. Rename it cacert.pem.
  3. Configure curl.cainfo in php.ini with the full path to the file downloaded in step 2.
  4. Restart Apache.

It will be worked perfectly.

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