HP Cloud PHP Bindings

Code your way into the HP Cloud with the HPCloud-PHP bindings. We've already added support for Identity Services, Object Storage, Content Distribution Network (CDN), Relational Database for MySQL (DBaaS), and we're just getting started.

View on GitHub Download now

Quickly connect your PHP apps to the HP Cloud and the HPCloud-PHP library.

Thinking of You...

The cloud is supposed to simplify our lives, right? We want our library to make it easy for developers to build amazing apps in the cloud – without any migraines. So when we built this library, we were thinking of you. (Well, not you specifically, but in that general sort of way.)

Store It In The Cloud

With a few lines of PHP, store your files in the cloud. You can configure private, public, and even CDN-backed object storage containers.

Keep It Simple

We believe a good API is a simple API. So we fully integrated with the PHP core. Using stream wrappers, you can be reading to and writing to Object Storage in a matter of minutes.

Only As Good As Its Documentation

Nothing is more frustrating than working with undocumented code. Time that could be spent building cool stuff is wasted hunting through somebody else's source code. So we documented everything we could. Because we'd rather you spent time making something awesome.

Built For You

Admittedly, our imaginations are limited. We haven't thought of every use case, and we don't know what you are capable of building. But we'd love to hear about what you're doing, help solve problems, and evolve this library to better meet your needs. Feel free to drop requests into the issue queue or hunt us down in #hpcloud on irc.freenode.net. And, of course, we're always at HPCloud.com.

Sign Up for HP Cloud Sign Up Now

Two APIs In One

Sometimes you need quick and easy. Sometimes you need deep and thorough. We tried to build a library that accomodates both cases.

Pedal to the Metal

We took advantage of PHP's built-in stream wrapper feature to expose object storage to PHP's file and stream functions. What does that mean? It means connecting to the cloud is as easy as this:

// Get all set up.
require_once '/HPCloud/Bootstrap.php';
use \HPCloud\Bootstrap;

// Provide credentials
$settings = array(
  'account' => YOUR_ACCESS_KEY_ID,
  'secret' => YOUR_SECRET_KEY,
  'tenantid' => YOUR_TENANT_ID,
  'endpoint' => IDENTITY_SERVICES_URL,

// Create a new file and write it to the object store.
$newfile = fopen('swift://mycontainer/my_file.txt', 'w');
fwrite($newfile, "Good Morning!");

// Check for an object:
if (file_exists('swift://mycontainer/my_file.txt')) {
  print "Found my_file.txt." . PHP_EOL;

// Get an entire object at once:
$file = file_get_contents('swift://mycontainer/my_file.txt');
print 'File: ' . $file . PHP_EOL;

Once the library is loaded and ready, everything else is just plain old PHP.

Make Every Bit Count

Sophisticated applications need sophisticated APIs to build against. So in addition to the stream wrapper library, the HPCloud-PHP library provides an feature-rich object-oriented interface.

This part of the library gives you access to every piece of HP Cloud functionality that we could get our hands on. Right now, we have full support for Identity Services (the authentication and authorization service), Object Storage, and the Content Distribution Network (CDN) Service.

These are the services we use most often, so we started there. But we're still going. As HP Cloud rolls out new services (and there are a lot coming), we're adding support.

So what does this API look like? Here is a brief example:

// Set up.
require_once '/HPCloud/Bootstrap.php';
use \HPCloud\Bootstrap;

// Authenticate to HP Cloud
$account = 'ADD ACCESS KEY HERE';
$secret = 'ADD KEY HERE';
$tenantId = 'ADD TENANT ID HERE';
$endpoint = 'ADD ENDPOINT URL HERE';

$idService = new \HPCloud\Services\IdentityServices($endpoint);
$token = $idService->authenticateAsAccount($account, $secret, $tenantId);

// Connect to Object Storage.
$catalog = $idService->serviceCatalog();
$store = ObjectStorage::newFromServiceCatalog($catalog, $token);

// Create a Container.
$container = $store->container('Example');

// Create an Object.
$name = 'hello.txt';
$content = 'Hello World';
$mime = 'text/plain';
$localObject = new Object($name, $content, $mime);

// Put the Object in the Container.

// And get the Object back out again.
$object = $container->proxyObject('hello.txt');

printf("Name: %s \n", $object->name());
printf("Size: %d \n", $object->contentLength());
printf("Type: %s \n", $object->contentType());
print $object->content() . PHP_EOL;

This example shows a few of the basics for working with HP Cloud using the HPCloud-PHP library. But there is plenty more.

Ready to Learn More?

Take a look at the documentation. We have tutorials for the stream wrappers and for the object oriented library. And we have over 200 pages of detailed developer documentation.

We Who Built This

The HPCloud-PHP library is written and maintained by the Customer Experience team in HP's Cloud Services. In CX, we have a goal: We want developers to love working with HP Cloud. Stop in at http://community.hpcloud.com to ask us questions and let us know how we're doing.