ceph API之PHP的客户端连接

 下载v2的SDK开发包http://pear.amazonwebservices.com/get/sdk-latest.zip

解压到目录下:

unzip sdk-latest.zip && cd sdk-latest

编辑sdk.class.php

vim sdk.class.php

第157和162行
        /**  
         * The state of SSL/HTTPS use.
         */
        public $use_ssl = false;   #修改属性 调用类时不使用https访问

        /**  
         * The state of SSL certificate verification.
         */
        public $ssl_verification = false;  #修改属性 调用类时不使用https访问
将他们全部改为false,如果为true你需要使用ssl来连接默认连接443端口,需要配置证书

编写一个测试php:

vim test.php

<?php
define('AWS_KEY', 'place access key here');
define('AWS_SECRET_KEY', 'place secret key here');
define('AWS_CANONICAL_ID', 'your DHO Username');
define('AWS_CANONICAL_NAME', 'Also your DHO Username!');
$HOST = 'cephcloud.com';   #这里可以使用域名和IP

// require the amazon sdk for php library
require_once 'xxxxx/sdk.class.php';   #修改路径 test需要调用sdk包里面的sdk.class.php

// Instantiate the S3 class and point it at the desired host
$Connection = new AmazonS3(array(
        'key' => 'xxxxxxxxxxxxx',    #连接密匙
        'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxx',  #接入密匙
      //  'canonical_id' => AWS_CANONICAL_ID,
      //  'canonical_name' => AWS_CANONICAL_NAME,
));
$Connection->set_hostname($HOST);
$Connection->allow_hostname_override(false);

// Set the S3 class to use objects.dreamhost.com/bucket
// instead of bucket.objects.dreamhost.com
$Connection->enable_path_style();


$ListResponse = $Connection->list_buckets();
$Buckets = $ListResponse->body->Buckets->Bucket;
foreach ($Buckets as $Bucket) {
        echo $Bucket->Name . "	" . $Bucket->CreationDate . "
";
}

结果输出:

查询出桶的信息

xxx_bucket	2018-01-12T01:29:56.261Z
xxx_bbbbb	2018-01-12T01:30:54.960Z
xxxxx_bucket	2018-01-12T01:30:32.134Z