HPCloud-PHP
1.2.0
PHP bindings for HPCloud and OpenStack services.
|
Provides CDN services for ObjectStorage. More...
Public Member Functions | |
__construct ($token, $endpoint) | |
Build a new CDN object. | |
containers ($enabledOnly=NULL) | |
Get a list of containers that the CDN system knows of. | |
container ($name) | |
Get a container by name. | |
enable ($name, $ttl=NULL, &$created=FALSE) | |
Enable a container. | |
update ($name, $attrs) | |
Set attributes on a CDN container. | |
delete ($name) | |
Attempt to remove a container from CDN. |
Static Public Member Functions | |
static | newFromIdentity ($identity, $region=CDN::DEFAULT_REGION) |
Create a new instance from an IdentityServices object. | |
static | newFromServiceCatalog ($catalog, $token, $region=CDN::DEFAULT_REGION) |
Create a new CDN object based on a service catalog. |
Public Attributes | |
const | SERVICE_TYPE = 'hpext:cdn' |
The name of the CDN service type. | |
const | API_VERSION = '1.0' |
The API version. | |
const | DEFAULT_REGION = 'region-a.geo-1' |
Protected Member Functions | |
modifyContainer ($name, $method, $headers=array(), $qstring= '') | |
Run the given method on the given container. |
Protected Attributes | |
$url | |
The URL to the CDN endpoint. | |
$token | |
The authentication/authorization token. |
Provides CDN services for ObjectStorage.
CDN stands for "Content Distribution Network." It provides distributed caching in the cloud. When a Container is CDN-enabled, objects will be stored not just in the ObjectStorage, but temporary cached copies will be stored on servers around the world.
CDN is an HPCloud extension service, and is not presently part of OpenStack proper. The current REST API documentation can be found at http://api-docs.hpcloud.com/
Usage
The CDN service functions as an add-on to ObjectStorage. It adds a caching layer. So terms used here, such as Container and Object, refer to the ObjectStorage items.
For the most part, CDN operates on the Container level. You can choose to tell the CDN about a particular Container in ObjectStorage, and it will cache items in that container.
The CDN service keeps a list of ObjectStorage Containers that it knows about. CDN does not automatically discover ObjectStorage Containers; you must tell CDN about the ObjectStorage instances you want it to know about. This is done using CDN::enable().
Once the CDN service knows about an ObjectStorage Container, it will begin caching objects in that container.
This library gives the the ability to do the following:
Example
__construct | ( | $token, | |
$endpoint | |||
) |
Build a new CDN object.
This object facilitates communication with the CDN cloud service.
This creates a new CDN object that will view as its endpoint the server with the URL $endpoint, which has the form:
On older SwiftAuth-based services, the token should be the swauth token. On newer releaes, the token is retrieved from IdentityServices.
string | $endpoint | The URL of the CDN service. It should look something like this: https://cdnmgmt.rndd.aw1.hpcloud.net/v1.0/72020596871800 |
string | $token | The authentication token. This can be retrieved from IdentityServices::token(). |
Definition at line 256 of file CDN.php.
References $endpoint, and CDN\$token.
container | ( | $name | ) |
Get a container by name.
Example return value:
string | $name | The name of the container to fetch. |
array |
Definition at line 370 of file CDN.php.
References $container, $name, and CDN\containers().
containers | ( | $enabledOnly = NULL | ) |
Get a list of containers that the CDN system knows of.
This returns a list of ObjectStorage Containers that the CDN service knows of. These containers can be either enabled or disabled.
The CDN service does not attempt to discover all of the containers from a Swift endpoint. Instead, it passively acquires a list of containers (added via, for example, enabledContainer()).
Once a container has been added to the CDN service, it can be in one of two states:
cdn_enabled=TRUE
)cdn_enabled=FALSE
)This listing will retrieve both enabled and disabled unless $enabledOnly is set to TRUE.
Returned data is in this format:
enabled_only
to the endpoint. The endpoint may or may not honor this.boolean | $enabledOnly | If this is set to TRUE, then only containers that are CDN-enabled will be returned. |
array |
HPCloud::Exception | An HTTP-level exception on error. |
Definition at line 320 of file CDN.php.
References CDN\$url.
Referenced by CDN\container().
delete | ( | $name | ) |
Attempt to remove a container from CDN.
This will remove a container from CDN services, completely stopping all caching on that container.
Deleted containers will no longer show up in the containers() list, nor will they be accessible via container().
Deleted containers can be added back with enable().
string | $name | The Container name. |
boolean |
HPCloud::Exception | Any of the HTTP error subclasses can be thrown. |
Definition at line 556 of file CDN.php.
References $name, and CDN\modifyContainer().
enable | ( | $name, | |
$ttl = NULL , |
|||
& | $created = FALSE |
||
) |
Enable a container.
This adds the container to the CDN service and turns on caching.
In the CDN API, there are two meanings for the term "enable":
This method does the first – it adds a container to the CDN service. It so happens that adding a container also enables (in the second sense) the container. (This is a feature of the remote service, not the API).
Enabling and disabling (in the second sense) are considered temporary operations to switch on and off caching on a particular container. Both of these operations are done with the update() method.
The endpoint is supposed to return different results based on the above; accordingly this method should return TRUE if the container was added to the list, and FALSE if it was already there. HOWEVER, in some versions of the CDN service the endpoint returns the same code for both operations, so the result cannot be relied upon.
string | $name | The name of the container. |
int | $ttl | Time to live. The number of seconds an object may stay in the cache. This is the maximum amount of time. There is, however, no assurance that the object will remain for the full TTL. 15 minutes is the minimum time. Five years is the max. |
boolean | $created | If this is passed, then its value will be set to TRUE if the container was created in the CDN, or FALSE if the container already existed in CDN. |
string |
HPCloud::Exception | Several HTTP-level exceptions can be thrown. |
Definition at line 431 of file CDN.php.
References $name, CDN\$url, and CDN\modifyContainer().
|
protected |
Run the given method on the given container.
Checks to see if the expected result is returned.
string | $name | The name of the container. |
string | $method | The appropriate HTTP verb. |
int | $expects | The expected HTTP code. |
Definition at line 573 of file CDN.php.
References $name, CDN\$token, and CDN\$url.
Referenced by CDN\delete(), CDN\enable(), and CDN\update().
|
static |
Create a new instance from an IdentityServices object.
This builds a new CDN instance form an authenticated IdentityServices object.
In the service catalog, this selects the first service entry for CDN. At this time, that is sufficient.
HPCloud::Services::IdentityServices | $identity | The identity to use. |
boolean | |
HPCloud::Storage::CDN |
Definition at line 160 of file CDN.php.
References CDN\newFromServiceCatalog().
|
static |
Create a new CDN object based on a service catalog.
The IdentityServices class contains a service catalog, which tracks all services that the present account can access. The service catalog contains data necessary to connect to a CDN endpoint. This builder simplifies the process of creating a new CDN by accepting a service catalog and discovering the CDN service automatically.
In the vast majority of cases, this is the easiest way to proceed. If, however, a service catalog has multiple CDN instances (a possibility, though not currently supported), the present method has no means of determining which should be used. It simply chooses the first CDN service endpoint.
This uses the tenant ID that is found in the service catalog.
Either of the following work:
array | $catalog | A service catalog; see HPCloud::Services::IdentityServices::serviceCatalog(). |
string | $token | The token. |
boolean | |
HPCloud::Storage::CDN |
Definition at line 208 of file CDN.php.
References $catalog, $endpoint, and CDN\$token.
Referenced by CDN\newFromIdentity().
update | ( | $name, | |
$attrs | |||
) |
Set attributes on a CDN container.
This updates the attributes (that is, properties) of a container.
The following attributes are supported:
Future versions of the CDN service will likely provide other properties.
string | $name | The name of the container. |
array | $attrs | An associative array of attributes. |
boolean |
HPCloud::Exception | Possibly throws one of the HTTP exceptions. |
Definition at line 467 of file CDN.php.
References $name, and CDN\modifyContainer().
|
protected |
The authentication/authorization token.
Definition at line 141 of file CDN.php.
Referenced by CDN\__construct(), CDN\modifyContainer(), and CDN\newFromServiceCatalog().
|
protected |
The URL to the CDN endpoint.
Definition at line 137 of file CDN.php.
Referenced by CDN\containers(), CDN\enable(), and CDN\modifyContainer().
const SERVICE_TYPE = 'hpext:cdn' |