#native_company# #native_desc#
#native_cta#

Taking Advantage of Simple Cloud with the Zend Cloud Component

By W. Jason Gilmore
on January 24, 2011

Although still in their infancy, cloud-based services are already making an undeniable impact within businesses large and small. After all, the idea of reducing otherwise significant capital expenditures on hardware, software and service development by moving application services to a utility- or subscription-based model is pretty appealing, particularly so for small companies lacking the necessary manpower to manage these resources internally, or for startups who might need to rapidly provision new servers in order to meet sudden and growing demand for a popular new service.
The nebulous nature of the virtualized cloud infrastructure also makes it possible to migrate from one solution to another should a competing offering advertise a more attractive pricing structure or superior services to your currently chosen solution. At least that’s the general idea. The challenge happens to reside within the client code, because the most commonly integrated cloud APIs are tied to a specific cloud service. This dilemma is apparent even within otherwise DRY-oriented framework solutions such as the Zend Framework, which offers substantial cloud support through a variety of different components, among them Zend_Service_Amazon_S3 and Zend_Service_WindowsAzure. Therefore, if you wanted to switch from S3 to Azure, you would need to refactor your code to use the Zend_Service_WindowsAzure-specific API.
In an effort to eliminate this inconvenience several companies (among them Zend, Microsoft, and IBM) have banded together to create the Simple Cloud API. The Simple Cloud API offers a unified interface for document storage, file storage, and simple queue services, and currently supports several of the most popular service vendors, including Amazon, Windows Azure, and Nirvanix. Zend has already moved quickly to incorporate support for Simple Cloud into the Zend Framework, greatly reducing the barriers and complexity involved in moving from one service to another, or using multiple vendors within the same application.

Introducing Zend_Cloud

Available since the 1.11 release, the Zend_Cloud component offers a unified interface to several of the aforementioned services. It works identically to other Zend Framework adapter-oriented components, requiring you to use a factory pattern to specify the desired concrete adapter class. From there you can use the unified interface to interact with the desired service. For instance, this is how you would use Zend_Cloud to instantiate the Amazon S3-specific adapter:
$storage = Zend_Cloud_StorageService_Factory::getAdapter(array(
  Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY => 'Zend_Cloud_StorageService_Adapter_S3',
  Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY   => 'MY_ACCESS_KEY',
  Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY   => 'MY_SECRET_ACCESS_KEY'
));
Of course, you’ll need to swap out the AWS_ACCESS_KEY and AWS_SECRET_KEY placeholders with your respective keys. Further, rather than embed these keys within your controller actions, consider storing them in your application’s application.ini file and referencing them within your actions as desired. See the article Introducing the Zend Framework’s Application Configuration Component for more information about this useful feature.