【PHP SDK for OpenStack/Rackspace APIs】使用對象儲存服務

來源:互聯網
上載者:User
【PHP SDK for OpenStack/Rackspace APIs】使用Object Storage Service服務

Swift是OpenStack的Object Storage Service服務。在php-opencloud庫中,通過connection對象建立的ObjectStore類(OpenStack或Rackspace)來存取。

例如:

$cloud = new \OpenCloud\OpenStack(array(    'username'=>'{username}','password'=>'{password}'));$swift = $cloud->ObjectStore('cloudFiles','DFW');
使用新建立的$swift,你可以使用不同的Object Storage Service組件。

最進階別的Object Storage Service組件執行個體是Container,Container是對象的集合名稱,與檔案系統中的目錄和檔案夾類似(實際上並不等同)。

所有的對象都儲存在Container中。

在一個Object Storage Service執行個體中列舉所有Container

ContainerList對象是Container對象的集合。列舉Object Storage Service執行個體中的所有Container:

$containers = $swift->ContainerList();while($container = $containers->Next())    printf("%s\n", $container->name);
就像其他的對象集合,這也支援First(), Next()和Size()方法。

建立一個新Container

使用上面新建立的$swift對象的Container()方法建立一個新的(空的)的container。

$mycontainer = $swift->Container();
將該Container儲存到Object Storage Service執行個體中,使用Create()方法:

$mycontainer->Create('MyContainerName');
name不是必須在Create()方法中,如果name已經被設定的話。直接在方法中指定名稱也是很方便的。

$mycontainer->name = 'MyContainerName';$mycontainer->Create();
檢索已存在的Container

如果你傳遞一個參數到ObjectStore對象的Container()方法中,可以檢索一個已存在的Container:

$oldcontainer = $swift->Container('SomeOldContainer');

在這種情況下,關於SomeOldContainer的資訊將被檢索。這包含Container的metadata資訊。

printf("Container %s has %d object(s) consuming %d bytes\n",    $oldcontainer->name, $oldcontainer->count, $oldcontainer->bytes);

刪除Container

Delete()方法刪除Container

$oldcontainer->Delete();
請注意,Container被刪除時必須是空的,也就是說必須沒有對象與它相關聯。

更新Container

在後台,容器建立和更新方式完全相同。你可以使用Create()方法來更新Container;然而,Update()方法也被作為Create()方法的別名而存在,因為這在語意學上可能不同(在你的程式中):

$oldcontainer->metadata->update_time = time();$oldcontainer->Update();
翻譯自:https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/objectstore.md

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.