Home > Backend Development > PHP Tutorial > [PHP SDK for OpenStack/Rackspace APIs]Using Object Storage Service_PHP Tutorial

[PHP SDK for OpenStack/Rackspace APIs]Using Object Storage Service_PHP Tutorial

WBOY
Release: 2016-07-15 13:21:46
Original
942 people have browsed it

Swift is OpenStack’s object storage service. In the php-opencloud library, it is accessed through the ObjectStore class (OpenStack or Rackspace) created by the connection object.

For example:
$cloud = new OpenCloudOpenStack(array(
'username'=>'{username}','password'=>'{password}'));
$swift = $cloud->ObjectStore('cloudFiles','DFW');
Using the newly created $swift, you can use different object storage components.
The highest-level object storage component instance is Container. Container is the collection name of objects, which is similar to directories and folders in the file system (not actually equivalent).
All objects are saved in Container.
List all Containers in an object storage instance
ContainerList object is a collection of Container objects. List all Containers in the object storage instance:
$containers = $swift->ContainerList();
while($container = $containers->Next())
printf("%sn", $container->name);
Like other object collections, this also supports First(), Next() and Size() methods.
Create a new Container
Create a new (empty) container using the Container() method of the newly created $swift object above.
$mycontainer = $swift->Container();
Save the Container to the object storage instance and use the Create() method:
$mycontainer->Create('MyContainerName');
name does not have to be in the Create() method if name has been set. It is also convenient to specify the name directly in the method.
$mycontainer->name = 'MyContainerName';
$mycontainer->Create();
Retrieve existing Container
If you pass a parameter to the Container() method of the ObjectStore object, you can retrieve an existing Container:
$oldcontainer = $swift->Container('SomeOldContainer');
In this case, information about SomeOldContainer will be retrieved. This contains the Container's metadata information.
printf("Container %s has %d object(s) consuming %d bytesn",
$oldcontainer->name, $oldcontainer->count, $oldcontainer->bytes);
Delete Container
Delete() method deletes Container
$oldcontainer->Delete();
Please note that the Container must be empty when it is deleted, that is, there must be no object associated with it.
Update Container
Under the hood, containers are created and updated exactly the same way. You can use the Create() method to update a Container; however, the Update() method is also used as an alias for the Create() method because the semantics may be different (in your program):
$oldcontainer->metadata->update_time = time();
$oldcontainer->Update();

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477123.htmlTechArticleSwift is OpenStack’s object storage service. In the php-opencloud library, it is accessed through the ObjectStore class (OpenStack or Rackspace) created by the connection object. For example: $cloud = new OpenClou...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template