PHPSDKforOpenStack/RackspaceAPIs use object storage service

Source: Internet
Author: User
[PHPSDKforOpenStack/RackspaceAPIs] using object storage service Swift is the object storage service of OpenStack. In the php-opencloud Library, The ObjectStore class (OpenS [php sdk for OpenStack/Rackspace APIs] created through the connection object uses the object storage service

Swift is an object storage service of OpenStack. In the php-opencloud Library, access the ObjectStore class (OpenStack or Rackspace) created by the connection object.

For example:

$cloud = new \OpenCloud\OpenStack(array(    'username'=>'{username}','password'=>'{password}'));$swift = $cloud->ObjectStore('cloudFiles','DFW');
With the newly created $ swift, you can use different object storage components.

The instance of the highest level object storage component is Container, and Container is the set name of the object, which is similar to the directory and folder in the file system (in fact not the same ).

All objects are saved in the Container.

List all containers in an OSS instance

The ContainerList object is a collection of INER objects. List all containers in an OSS instance:

$containers = $swift->ContainerList();while($container = $containers->Next())    printf("%s\n", $container->name);
Like other object sets, this also supports the First (), Next () and Size () methods.

Create a new INER iner

Use the newly created $ swift object's Container () method to create a new (empty) container.

$mycontainer = $swift->Container();
Save the Container to the OSS instance and use the Create () method:

$mycontainer->Create('MyContainerName');
Name is not required in the Create () method, if the name has been set. It is convenient to specify a name directly in the method.

$mycontainer->name = 'MyContainerName';$mycontainer->Create();
Retrieve existing INER iner

If you pass a parameter to the objectiner () 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 includes the metadata information of the Container.

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

Delete Container

Delete () method to Delete the Container

$oldcontainer->Delete();
Note that the Container must be empty when it is deleted, that is, no object must be associated with it.

Update Container

In the background, the container creation and update methods are the same. You can use the Create () method to Update the Container. However, the Update () method is also used as the alias of the Create () method, because this may be different in semantics (in your program ):

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.