"PHP SDK for Openstack/rackspace APIs" uses object storage services

Source: Internet
Author: User
"PHP SDK for Openstack/rackspace APIs" uses object storage services

Swift is an object storage service for OpenStack. In the Php-opencloud library, the ObjectStore class (OpenStack or Rackspace) created by the Connection object is accessed.

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 highest-level object storage component instance is Container,container is the collection name of the object, similar to the directory and folder in the file system (not actually equivalent).

All objects are saved in the container.

Enumerating all container in an object storage instance

The Containerlist object is a collection of container objects. Enumerate all container in an object storage instance:

$containers = $swift->ContainerList();while($container = $containers->Next())    printf("%s\n", $container->name);
Just like other object collections, this also supports the 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, using the Create () method:

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

$mycontainer->name = 'MyContainerName';$mycontainer->Create();
retrieving a container that already exists

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 metadata information for the container.

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

Delete Container

Delete () method remove container

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

Update container

In the background, the container is created and updated exactly the same way. You can use the Create () method to update the container; However, the update () method is also present as an alias to the Create () method because it may be different in semantics (in your program):

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

  • Related Article

    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.