This is the documentation for the HPCloud PHP library.
Overview
HPCloud provides public cloud infrastructure that is business-grade, open source-based, and developer focused. Built on OpenStack, it provides many cloud-based services that developers can take advantage of when building robust and reliable websites.
The HPCloud-PHP library provides PHP developers with a fully tested, robust, and feature-rich library for working with the HPCloud services.
- Attention
- Making use of this library will require that you have several pieces of account information for your HPCloud account (or OpenStack account, if you're using this library with non-HP OpenStack implentations):
- account ID and secret key: For cases where you want account-wide authentication/authorization.
- username/password: Typically, this is the same username/password you use to access the HPCloud console.
- tenant ID: This associates an account or user with a bundle of services. You can find this information in your console.
- endpoint: You will need the URL to the HPCloud endpoint responsible for authenticating users. This can be found in your console.
(If you are not sure what the "HPCloud Console" is, head over to http://docs.hpcloud.com. There you will find some articles and videos explaining the HPCloud structure.)
Where To Start
Cruising a list of methods and classes is not exactly the best way to get started with a library. It's better to know where to start. Here's what we suggest:
- There are a few tutorials inside this documentation that will help you get started. One explains Stream Wrappers and the other the library itself.
- Connecting and logging in is almost inevitably going to be your first task. For that, you will want to look at IdentityServices.
- ObjectStorage (a.k.a. swift) is our cloud storage system. There are two ways to use it:
- You can explore the object oriented API, starting with ObjectStorage.
- You can use the PHP stream wrappers to access your object storage. This is explained in StreamWrapper.
Learn More
This documentation is intended to provide a detailed reference to the HPCloud-PHP library. But this ain't all we've got. Tutorials, videos, screencasts, a knowledge base, and active community forums are just a click away.
Head over to http://docs.hpcloud.com to find these and other resources.
Or maybe you'd just like to see a couple of examples.
Basic Example: Stream Wrappers
The super-simple stream API:
<?php
require 'HPCloud/Bootstrap.php';
$cxt = stream_context_create(array(
'username' => 'matthew.butcher@hp.com',
'password' => 'secret',
'tenantid' => '123456',
'endpoint' => 'http://url.from.hpcloud.com/',
));
$myObject = file_get_contents('swift://mycontainer/foo.txt', FALSE, $cxt);
?>
With stream wrapper support, you can transparently read and write files to the HPCloud ObjectStorage service without using any fancy API at all. Use the normal file methods like this:
Basic Example: Identity Services
Stream wrappers are nice and all, but some of us love fancy APIs. So here's an example using the full API to log in and then dump a list of services that are available to you:
<?php
require 'HPCloud/Bootstrap.php';
use \HPCloud\Services\IdentityServices;
$identity = new IdentityServices('http://get.url.from.hpcloud.com');
$secret = 'dgasgasd';
?>
- Our classes use PHP namespaces to organize components. If you've never used them before, don't worry. They're easy to get the hang of.
- The Bootstrap class handles setting up HPCloud services. Read about it at HPCloud::Bootstrap.
- The IdentityServices class handles authenticating to HP, discovering services, and providing access to your account. HPCloud::Services::IdentityServices explains the details, but here are a few functions you'll want to know:
Basic Example: Object Storage
Assuming you have an object storage instance available in your service catalog, we could continue on with something like this:
<?php
print_r($objectStore->containers());
print_r($container->objects());
$obj = $container->object('example.txt');
print $obj->content();
print $obj;
?>
This shows you a few methods for accessing objects and containers on your HPCloud::Storage::ObjectStorage account. There are many functions for creating and modifying containers and objects, too.