PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/userguide/ObjectStore/USERGUIDE.md

https://github.com/unarmedwombat/php-opencloud
Markdown | 596 lines | 412 code | 184 blank | 0 comment | 0 complexity | 8abec7a246d2d66d5929b12af2bce98e MD5 | raw file
Possible License(s): Apache-2.0
  1. # The Complete User Guide to the Object Store Service
  2. **Object Store** is an object-based storage system that stores content and metadata as objects in a cloud.
  3. ## Prerequisites
  4. ### Client
  5. To use the object store service, you must first instantiate a `OpenStack` or `Rackspace` client object.
  6. * If you are working with a vanilla OpenStack cloud, instantiate an `OpenCloud\OpenStack` client as shown below.
  7. ```php
  8. use OpenCloud\OpenStack;
  9. $client = new OpenStack('<OPENSTACK CLOUD IDENTITY ENDPOINT URL>', array(
  10. 'username' => '<YOUR RACKSPACE CLOUD ACCOUNT USERNAME>',
  11. 'apiKey' => '<YOUR RACKSPACE CLOUD ACCOUNT API KEY>'
  12. ));
  13. ```
  14. * If you are working with the Rackspace cloud, instantiate a `OpenCloud\Rackspace` client as shown below.
  15. ```php
  16. use OpenCloud\Rackspace;
  17. $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
  18. 'username' => '<YOUR RACKSPACE CLOUD ACCOUNT USERNAME>',
  19. 'apiKey' => '<YOUR RACKSPACE CLOUD ACCOUNT API KEY>'
  20. ));
  21. ```
  22. ### Object Store Service
  23. All operations on the object store are done via an object store service object.
  24. ```php
  25. $region = 'DFW';
  26. $objectStoreService = $client->objectStoreService(null, $region);
  27. ```
  28. In the example above, you are connecting to the ``DFW`` region of the cloud. Any containers and objects created with this `$objectStoreService` instance will be stored in that cloud region.
  29. ## Containers
  30. A **container** defines a namespace for **objects**. An object with the same name in two different containers represents two different objects.
  31. For example, you may create a container called `logos` to hold all the image files for your blog.
  32. A container may contain zero or more objects in it.
  33. ### Create Container
  34. ```php
  35. $container = $objectStoreService->createContainer('logos');
  36. ```
  37. [ [Get the executable PHP script for this example](/samples/ObjectStore/create-container.php) ]
  38. ### Get Container Details
  39. You can retrieve a single container's details by using its name. An instance of `OpenCloud\ObjectStore\Resource\Container` is returned.
  40. ```php
  41. $container = $objectStoreService->getContainer('logos');
  42. /** @var $container OpenCloud\ObjectStore\Resource\Container **/
  43. ```
  44. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-container.php) ]
  45. ### List Containers
  46. You can retrieve a list of all your containers. An instance of `OpenCloud\Common\Collection\PaginatedIterator`
  47. is returned.
  48. ```php
  49. $containers = $objectStoreService->listContainers();
  50. foreach ($containers as $container) {
  51. /** @var $container OpenCloud\ObjectStore\Resource\Container **/
  52. }
  53. ```
  54. [ [Get the executable PHP script for this example](/samples/ObjectStore/list-containers.php) ]
  55. ### Set or Update Container Metadata
  56. You can set metadata on a container.
  57. ```php
  58. $container->saveMetadata(array(
  59. 'author' => 'John Doe'
  60. ));
  61. ```
  62. [ [Get the executable PHP script for this example](/samples/ObjectStore/set-container-metadata.php) ]
  63. ### Get Container Metadata
  64. You can retrieve the metadata for a container.
  65. ```php
  66. $containerMetadata = $container->getMetadata();
  67. ```
  68. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-container-metadata.php) ]
  69. ### Delete Container
  70. When you no longer have a need for the container, you can remove it.
  71. If the container is empty (that is, it has no objects in it), you can remove it as shown below:
  72. ```php
  73. $container->delete();
  74. ```
  75. [ [Get the executable PHP script for this example](/samples/ObjectStore/delete-container.php) ]
  76. If the container is not empty (that is, it has objects in it), you have two choices in how to remove it:
  77. * [Individually remove each object](#delete-object) in the container, then remove the container itself as shown above, or
  78. * Remove the container and all the objects within it as shown below:
  79. ```php
  80. $container->delete(true);
  81. ```
  82. [ [Get the executable PHP script for this example](/samples/ObjectStore/delete-container-recursive.php) ]
  83. ### Get Object Count
  84. You can quickly find out how many objects are in a container.
  85. ```php
  86. $containerObjectCount = $container->getObjectCount();
  87. ```
  88. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-container-object-count.php) ]
  89. In the example above, `$containerObjectCount` will contain the number of objects in the container represented by `$container`.
  90. ### Get Bytes Used
  91. You can quickly find out the space used by a container, in bytes.
  92. ```php
  93. $containerSizeInBytes = $container->getBytesUsed();
  94. ```
  95. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-container-bytes-used.php) ]
  96. In the example above, `$containerSizeInBytes` will contain the space used, in bytes, by the container represented by `$container`.
  97. ### Container Quotas
  98. #### Set Quota for Number of Objects
  99. You can set a quota for the maximum number of objects that may be stored in a container.
  100. ```php
  101. $maximumNumberOfObjectsAllowedInContainer = 25;
  102. $container->setCountQuota($maximumNumberOfObjectsAllowedInContainer);
  103. ```
  104. [ [Get the executable PHP script for this example](/samples/ObjectStore/set-container-count-quota.php) ]
  105. #### Set Quota for Total Size of Objects
  106. You can set a quota for the maximum total space (in bytes) used by objects in a container.
  107. ```php
  108. use OpenCloud\Common\Constants\Size;
  109. $maximumTotalSizeOfObjectsInContainer = 5 * Size::GB;
  110. $container->setBytesQuota($maximumTotalSizeOfObjectsInContainer);
  111. ```
  112. [ [Get the executable PHP script for this example](/samples/ObjectStore/set-container-bytes-quota.php) ]
  113. #### Get Quota for Number of Objects
  114. You can retrieve the quota for the maximum number of objects that may be stored in a container.
  115. ```php
  116. $maximumNumberOfObjectsAllowedInContainer = $container->getCountQuota();
  117. ```
  118. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-container-count-quota.php) ]
  119. #### Get Quota for Total Size of Objects
  120. You can retrieve the quota for the maximum total space (in bytes) used by objects in a container.
  121. ```php
  122. $maximumTotalSizeOfObjectsAllowedInContainer = $container->getBytesQuota();
  123. ```
  124. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-container-bytes-quota.php) ]
  125. ## Objects
  126. An **object** (sometimes referred to as a file) is the unit of storage in an Object Store. An object is a combination of content (data) and metadata.
  127. For example, you may upload an object named `php-elephant.jpg`, a JPEG image file, to the `logos` container. Further, you may assign metadata to this object to indicate that the author of this object was someone named Jane Doe.
  128. ### Upload Object
  129. Once you have created a container, you can upload objects to it.
  130. ```php
  131. $localFileName = '/path/to/local/php-elephant.jpg';
  132. $remoteFileName = 'php-elephant.jpg';
  133. $fileData = fopen($localFileName, 'r');
  134. $container->uploadObject($remoteFileName, $fileData);
  135. ```
  136. [ [Get the executable PHP script for this example](/samples/ObjectStore/upload-object.php) ]
  137. In the example above, an image file from the local filesystem (`path/to/local/php-elephant.jpg`) is uploaded to a container in the Object Store.
  138. Note that while we call `fopen` to open the file resource, we do not call `fclose` at the end. The file resource is automatically closed inside the `uploadObject` call.
  139. It is also possible to upload an object and associate metadata with it.
  140. ```php
  141. use OpenCloud\ObjectStore\Resource\DataObject;
  142. $localFileName = '/path/to/local/php-elephant.jpg';
  143. $remoteFileName = 'php-elephant.jpg';
  144. $metadata = array('author' => 'Jane Doe');
  145. $customHeaders = array();
  146. $metadataHeaders = DataObject::stockHeaders($metadata);
  147. $allHeaders = $customHeaders + $metadataHeaders;
  148. $fileData = fopen($localFileName, 'r');
  149. $container->uploadObject($remoteFileName, $fileData, $allHeaders);
  150. ```
  151. [ [Get the executable PHP script for this example](/samples/ObjectStore/upload-object-with-metadata.php) ]
  152. Note that while we call `fopen` to open the file resource, we do not call `fclose` at the end. The file resource is automatically closed inside the `uploadObject` call.
  153. #### Pseudo-hierarchical Folders
  154. Although you cannot nest directories in an Object Store, you can simulate a hierarchical structure within a single container by adding forward slash characters (`/`) in the object name.
  155. ```php
  156. $localFileName = '/path/to/local/php-elephant.jpg';
  157. $remoteFileName = 'languages/php/elephant.jpg';
  158. $fileData = fopen($localFileName, 'r');
  159. $container->uploadObject($remoteFileName, $fileData);
  160. ```
  161. [ [Get the executable PHP script for this example](/samples/ObjectStore/pseudo-hierarchical-folders.php) ]
  162. In the example above, an image file from the local filesystem (`/path/to/local/php-elephant.jpg`) is uploaded to a container in the Object Store. Within that container, the filename is `languages/php/elephant.jpg`, where `languages/php/` is a pseudo-hierarchical folder hierarchy.
  163. Note that while we call `fopen` to open the file resource, we do not call `fclose` at the end. The file resource is automatically closed inside the `uploadObject` call.
  164. #### Upload Multiple Objects
  165. You can upload more than one object at a time to a container.
  166. ```php
  167. $objects = array(
  168. array(
  169. 'name' => 'php-elephant.jpg',
  170. 'path' => '/path/to/local/php-elephant.jpg'
  171. ),
  172. array(
  173. 'name' => 'python-snake.jpg',
  174. 'path' => '/path/to/local/python-snake.jpg'
  175. ),
  176. a
  177. );
  178. $container->uploadObjects($objects);
  179. ```
  180. [ [Get the executable PHP script for this example](/samples/ObjectStore/upload-multiple-objects.php) ]
  181. In the above example, the contents of two files present on the local filesystem are uploaded as objects to the container referenced by `$container`.
  182. Instead of specifying the `path` key in an element of the `$objects` array, you can specify a `body` key whose value is a string or a stream representation.
  183. Finally, you can pass headers as the second parameter to the `uploadObjects` method. These headers will be applied to every object that is uploaded.
  184. ```
  185. $metadata = array('author' => 'Jane Doe');
  186. $customHeaders = array();
  187. $metadataHeaders = DataObject::stockHeaders($metadata);
  188. $allHeaders = $customHeaders + $metadataHeaders;
  189. $container->uploadObjects($objects, $allHeaders);
  190. ```
  191. [ [Get the executable PHP script for this example](/samples/ObjectStore/upload-multiple-objects-with-metadata.php) ]
  192. In the example above, every object referenced within the `$objects` array will be uploaded with the same metadata.
  193. ### Large Objects
  194. If you want to upload objects larger than 5GB in size, you must use a different upload process.
  195. ```php
  196. $options = array(
  197. 'name' => 'san_diego_vacation_video.mp4',
  198. 'path' => '/path/to/local/videos/san_diego_vacation.mp4'
  199. );
  200. $objectTransfer = $container->setupObjectTransfer($options);
  201. $objectTransfer->upload();
  202. ```
  203. [ [Get the executable PHP script for this example](/samples/ObjectStore/upload-large-object.php) ]
  204. The process shown above will automatically partition your large object into small chunks and upload them concurrently to the container represented by `$container`.
  205. You can tune the parameters of this process by specifying additional options in the `$options` array. Here is a complete listing of keys that can be specified in the `$options` array:
  206. | Key name | Description | Data Type | Required? | Default Value | Example |
  207. | -------------- | --------------- | ------------- | -------------- | ------------------ | ----------- |
  208. | `name` | Name of large object in container | String | Yes | - | `san_diego_vacation_video.mp4` |
  209. | `path` | Path to file containing object data on local filesystem | String | One of `path` or `body` must be specified | - | `/path/to/local/videos/san_diego_vacation.mp4` |
  210. | `body` | String or stream representation of object data | String \| Stream | One of `path` or `body` must be specified | - | `... lots of data ...` |
  211. | `metadata` | Metadata for the object | Associative array of metadata key-value pairs | No | `array()` | `array( "Author" => "Jane Doe" )` |
  212. | `partSize` | The size, in bytes, of each chunk that the large object is partitioned into prior to uploading | Integer | No | `1073741824` (1GB) | `52428800` (50MB) |
  213. | `concurrency` | The number of concurrent transfers to execute as part of the upload | Integer | No | `1` (no concurrency; upload chunks serially) | `10` |
  214. | `progress` | A [callable function or method](http://us1.php.net/manual/en/language.types.callable.php) which is called to report progress of the the upload. See [`CURLOPT_PROGRESSFUNCTION` documentation](http://us2.php.net/curl_setopt) for details on parameters passed to this callable function or method. | String (callable function or method name) | No | None | `reportProgress` |
  215. ### Auto-extract Archive Files
  216. You can upload a tar archive file and have the Object Store service automatically extract it into a container.
  217. ```php
  218. use OpenCloud\ObjectStore\Constants\UrlType;
  219. $localArchiveFileName = '/path/to/local/image_files.tar.gz';
  220. $remotePath = 'images/';
  221. $fileData = fopen($localArchiveFileName, 'r');
  222. $objectStoreService->bulkExtract($remotePath, $fileData, UrlType::TAR_GZ);
  223. ```
  224. [ [Get the executable PHP script for this example](/samples/ObjectStore/auto-extract-archive-files.php) ]
  225. In the above example, a local archive file named `image_files.tar.gz` is uploaded to an Object Store container named `images` (defined by the `$remotePath` variable).
  226. Note that while we call `fopen` to open a file resource, we do not call `fclose` at the end. The file resource is automatically closed inside the `bulkExtract` call.
  227. The third parameter to `bulkExtract` is the type of the archive file being uploaded. The acceptable values for this are:
  228. * `UrlType::TAR` for tar archive files, *or*,
  229. * `UrlType:TAR_GZ` for tar archive files that are compressed with gzip, *or*
  230. * `UrlType::TAR_BZ` for tar archive file that are compressed with bzip
  231. Note that the value of `$remotePath` could have been a (pseudo-hierarchical folder)[#psuedo-hierarchical-folders] such as `images/blog` as well.
  232. ### List Objects in a Container
  233. You can list all the objects stored in a container. An instance of `OpenCloud\Common\Collection\PaginatedIterator` is returned.
  234. ```php
  235. $objects = $container->objectList();
  236. foreach ($objects as $object) {
  237. /** @var $object OpenCloud\ObjectStore\Resource\DataObject **/
  238. }
  239. ```
  240. [ [Get the executable PHP script for this example](/samples/ObjectStore/list-objects.php) ]
  241. You can list only those objects in the container whose names start with a certain prefix.
  242. ```php
  243. $options = array(
  244. 'prefix' => 'php'
  245. );
  246. $objects = $container->objectList($options);
  247. ```
  248. [ [Get the executable PHP script for this example](/samples/ObjectStore/list-objects-with-params.php) ]
  249. In general, the `objectList()` method described above takes an optional parameter (`$options` in the example above). This parameter is an associative array of various options. Here is a complete listing of keys that can be specified in the `$options` array:
  250. | Key name | Description | Data Type | Required? | Default Value | Example |
  251. | -------------- | --------------- | ------------- | -------------- | ------------------ | ----------- |
  252. | `prefix` | Given a string x, limits the results to object names beginning with x. | String | No | | `php` |
  253. | `limit` | Given an integer n, limits the number of results to at most n values. | Integer | No | | 10 |
  254. | `marker` | Given a string x, returns object names greater than the specified marker. | String | No | | `php-elephant.jpg` |
  255. | `end_marker` | Given a string x, returns object names less than the specified marker. | String | No | | `python-snakes.jpg` |
  256. ### Retrieve Object
  257. You can retrieve an object and its metadata, given the object's container and name.
  258. ```php
  259. $objectName = 'php-elephant.jpg';
  260. $object = $container->getObject($objectName);
  261. /** @var $object OpenCloud\ObjectStore\Resource\DataObject **/
  262. $objectContent = $object->getContent();
  263. /** @var $objectContent Guzzle\Http\EntityBody **/
  264. // Write object content to file on local filesystem.
  265. $objectContent->rewind();
  266. $stream = $objectContent->getStream();
  267. $localFilename = tempnam("/tmp", 'php-opencloud-');
  268. file_put_contents($localFilename, $stream);
  269. ```
  270. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-object.php) ]
  271. In the example above, `$object` is the object named `php-elephant.jpg` in the container represented by `$container`. Further, `$objectContent` represents the contents of the object. It is of type [`Guzzle\Http\EntityBody`](http://api.guzzlephp.org/class-Guzzle.Http.EntityBody.html).
  272. ### Retrieve Object Metadata
  273. You can retrieve just an object's metadata without retrieving its contents.
  274. ```php
  275. $objectName = 'php-elephant.jpg';
  276. $object = $container->getPartialObject($objectName);
  277. $objectMetadata = $object->getMetadata();
  278. /** @var $objectMetadata \OpenCloud\Common\Metadata **/
  279. ```
  280. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-object-metadata.php) ]
  281. In the example above, while `$object` is an instance of `OpenCloud\ObjectStore\Resource\DataObject`, that instance is only partially populated. Specifically, only properties of the instance relating to object metadata are populated.
  282. ### Temporary URLs
  283. The Temporary URL feature allows you to create limited-time Internet addresses that allow you to grant limited access to your Object Store account. Using this feature, you can allow others to retrieve or place objects in your Object Store account for a specified amount of time. Access to the temporary URL is independent of whether or not your account is [CDN-enabled](#cdn-containers). Even if you do not CDN-enable a container, you can still grant temporary public access through a temporary URL.
  284. First, you must set the temporary URL secret on your account. This is a one-time operation; you only need to perform it the very first time you wish to use the temporary URLs feature.
  285. ```php
  286. $account->setTempUrlSecret();
  287. ```
  288. [ [Get the executable PHP script for this example](/samples/ObjectStore/set-account-temp-url-secret.php) ]
  289. Note that this operation is carried out on `$account`, which is an instance of `OpenCloud\ObjectStore\Resource\Account`, a class representing [your object store account](#accounts).
  290. The above operation will generate a random secret and set it on your account. Instead of a random secret, if you wish to provide a secret, you can supply it as a parameter to the `setTempUrlSecret` method.
  291. ```php
  292. $account->setTempUrlSecret('<SOME SECRET STRING>');
  293. ```
  294. [ [Get the executable PHP script for this example](/samples/ObjectStore/set-account-temp-url-secret-specified.php) ]
  295. Once a temporary URL secret has been set on your account, you can generate a temporary URL for any object in your Object Store.
  296. ```php
  297. $expirationTimeInSeconds = 3600; // one hour from now
  298. $httpMethodAllowed = 'GET';
  299. $tempUrl = $object->getTemporaryUrl($expirationTimeInSeconds, $httpMethodAllowed);
  300. ```
  301. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-object-temporary-url.php) ]
  302. In the example above, a temporary URL for the object is generated. This temporary URL will provide public access to the object for an hour (3600 seconds), as specified by the `$expirationTimeInSeconds` variable. Further, only GET HTTP methods will be allowed on this URL, as specified by the `$httpMethodAllowed` variable. The other value allowed for the `$httpMethodAllowed` variable would be `PUT`.
  303. You can also retrieve the temporary URL secret that has been set on your account.
  304. ```php
  305. $tempUrlSecret = $account->getTempUrlSecret();
  306. ```
  307. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-account-temp-url-secret.php) ]
  308. ### Update Object
  309. You can update an object's contents (as opposed to [updating its metadata](#update-object-metadata)) by simply re-[uploading the object](#upload-object) to its container using the same object name as before.
  310. ### Update Object Metadata
  311. You can update an object's metadata after it has been uploaded to a container.
  312. ```php
  313. $object->saveMetadata(array(
  314. 'author' => 'John Doe'
  315. ));
  316. ```
  317. [ [Get the executable PHP script for this example](/samples/ObjectStore/update-object-metadata.php) ]
  318. ### Copy Object
  319. You can copy an object from one container to another, provided the destination container already exists.
  320. ```php
  321. $object->copy('logos_copy/php.jpg');
  322. ```
  323. [ [Get the executable PHP script for this example](/samples/ObjectStore/copy-object.php) ]
  324. In the example above, both the name of the destination container (`logos_copy`)and the name of the destination object (`php.jpg`) have to be specified, separated by a `/`.
  325. ### Delete Object
  326. When you no longer need an object, you can delete it.
  327. ```php
  328. $object->delete();
  329. ```
  330. [ [Get the executable PHP script for this example](/samples/ObjectStore/delete-object.php) ]
  331. ### Bulk Delete
  332. While you can delete individual objects as shown above, you can also delete objects and empty containers in bulk.
  333. ```php
  334. $objectStoreService->bulkDelete(array(
  335. 'logos/php-elephant.png',
  336. 'logos/python-snakes.png',
  337. 'some_empty_container'
  338. ));
  339. ```
  340. [ [Get the executable PHP script for this example](/samples/ObjectStore/bulk-delete.php) ]
  341. In the example above, two objects (`some_container/object_a.png`, `some_other_container/object_z.png`) and one empty container (`some_empty_container`) are all being deleted in bulk via a single command.
  342. ## CDN Containers
  343. <strong><em>Note: The functionality described in this section is available only on the Rackspace cloud. It will not work as described when working with a vanilla OpenStack cloud.</em></strong>
  344. Any container can be converted to a CDN-enabled container. When this is done, the objects within the container can be accessed from anywhere on the Internet via a URL.
  345. ### Enable CDN Container
  346. To take advantage of CDN capabilities for a container and its objects, you must CDN-enable that container.
  347. ```php
  348. $container->enableCdn();
  349. ```
  350. [ [Get the executable PHP script for this example](/samples/ObjectStore/enable-container-cdn.php) ]
  351. ### Public URLs
  352. Once you have CDN-enabled a container, you can retrieve a publicly-accessible URL for any of its objects. There are four types of publicly-accessible URLs for each object. Each type of URL is meant for a different purpose. The sections below describe each of these URL types and how to retrieve them.
  353. #### HTTP URL
  354. You can use this type of URL to access the object over HTTP.
  355. ```
  356. $httpUrl = $object->getPublicUrl();
  357. ```
  358. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-cdn-object-http-url.php) ]
  359. #### Secure HTTP URL
  360. You can use this type of URL to access the object over HTTP + TLS/SSL.
  361. ```
  362. use OpenCloud\ObjectStore\Constants\UrlType;
  363. $httpsUrl = $object->getPublicUrl(UrlType::SSL);
  364. ```
  365. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-cdn-object-https-url.php) ]
  366. #### Streaming URL
  367. You can use this type of URL to stream a video or audio object using Adobe's HTTP Dynamic Streaming.
  368. ```
  369. use OpenCloud\ObjectStore\Constants\UrlType;
  370. $streamingUrl = $object->getPublicUrl(UrlType::STREAMING);
  371. ```
  372. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-cdn-object-streaming-url.php) ]
  373. #### IOS Streaming URL
  374. You can use this type of URL to stream an audio or video object to an iOS device.
  375. ```
  376. use OpenCloud\ObjectStore\Constants\UrlType;
  377. $iosStreamingUrl = $object->getPublicUrl(UrlType::IOS_STREAMING);
  378. ```
  379. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-cdn-object-ios-streaming-url.php) ]
  380. ### Disable CDN Container
  381. If you no longer need CDN capabilities for a container, you can disable them.
  382. ```php
  383. $container->disableCdn();
  384. ```
  385. [ [Get the executable PHP script for this example](/samples/ObjectStore/disable-container-cdn.php) ]
  386. ## Accounts
  387. An **account** defines a namespace for **containers**. An account can have zero or more containers in it.
  388. ### Retrieve Account
  389. You must retrieve the account before performing any operations on it.
  390. ```php
  391. $account = $objectStoreService->getAccount();
  392. ```
  393. ### Get Container Count
  394. You can quickly find out how many containers are in your account.
  395. ```php
  396. $accountContainerCount = $account->getContainerCount();
  397. ```
  398. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-account-container-count.php) ]
  399. ### Get Object Count
  400. You can quickly find out how many objects are in your account.
  401. ```php
  402. $accountObjectCount = $account->getObjectCount();
  403. ```
  404. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-account-object-count.php) ]
  405. In the example above, `$accountObjectCount` will contain the number of objects in the account represented by `$account`.
  406. ### Get Bytes Used
  407. You can quickly find out the space used by your account, in bytes.
  408. ```php
  409. $accountSizeInBytes = $account->getBytesUsed();
  410. ```
  411. [ [Get the executable PHP script for this example](/samples/ObjectStore/get-account-bytes-used.php) ]
  412. In the example above, `$accountSizeInBytes` will contain the space used, in bytes, by the account represented by `$account`.