DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Databases
  4. Getting Started with the Windows Azure SDK for PHP

Getting Started with the Windows Azure SDK for PHP

Maarten Balliauw user avatar by
Maarten Balliauw
·
Dec. 14, 10 · Interview
Like (0)
Save
Tweet
Share
13.04K Views

Join the DZone community and get the full member experience.

Join For Free

The Windows Azure platform is a flexible, cloud computing platform that lets you focus on solving business problems and addressing customer needs. It is a group of cloud technologies, each providing a specific set of services to application developers. The main components of the Windows Azure platform are the following:

  • Windows Azure, focuses on providing computation power in the form of web and worker roles and storage in the form of blob storage, table storage and the queue service.
  • SQL Azure, is a cloud-hosted relational database that is very similar to SQL Server.
  • Windows Azure AppFabric, focuses on integrating software that is hosted in different locations without having to compromise on security.

Each component can be leveraged from within your PHP application: the Windows Azure SDK for PHP provides a programming model for Windows Azure, the SQL Server Driver for PHP allows you to work with SQL Server and SQL Azure and the Windows Azure AppFabric SDK for PHP provides an API for working with Windows Azure AppFabric.

The Windows Azure platform components are not tied together: you may select the components that are useful for your specific application and situation, both for applications hosted on premise and on Windows Azure. For example, blob storage - the storage service providing massive scale-out storage on Windows Azure - can be used from an application you host on Windows Azure as well as from an application hosted on your current web server.

 

Developing for Windows Azure

To deploy your application and use Windows Azure services you will need an account (see the "get started" tutorial). For development purposes, an application can be developed on any platform using any IDE. However, you will always have to work with Windows Azure production storage unless you work on the Windows platform. When working with Windows, there is an option to install a local development cloud & storage environment on your machine. The Windows Azure SDK provides the Windows Azure development storage and additional features which make it easier to build & test applications. The SDK requires a version of Windows 7, Windows Vista Service Pack 1 or greater, or Windows Server 2008 with a version of SQL Server Express or SQL Server installed.

The download for the Windows Azure SDK can be found at http://msdn.microsoft.com/en-us/windowsazure/cc974146.aspx.

After installation, the development storage service can be started through the Start button, All programs, Windows Azure SDK, Development Storage.

Tools & SDK's

Next to the Windows Azure SDK and the Windows Azure SDK for PHP described further in this document, a number of other SDK's exist for working with Windows Azure from PHP.

The following tools are available:

image

Figure 1:  Tools and SDK's for working with Windows Azure from PHP

The following table is an overview of the available tools & SDK's:

Tool / SDK

Description

Windows Azure SDK

Provides development fabric & storage: simulated local cloud environment for development purposes.

Windows Azure SDK for PHP

Provides an API for working with Windows Azure storage and development storage as well as diagnostics.

Windows Azure Command-Line tools for PHP

Tool for packaging an application for deployment to Windows Azure or development fabric.

Windows Azure tools for Eclipse

Eclipse plugin providing an integrated experience for working with Windows Azure, storage, deploying applications, and so on.

SQL Server Driver for PHP

Provides connectivity with SQL Server and SQL Azure from PHP.

Azure AppFabric SDK for PHP

Provides an API for working with AppFabric access control & service bus from PHP.

Windows Azure Companion for PHP

Tool providing easy installation of popular PHP software on Windows Azure, such as WordPress, Drupal, phpBB, and others.

 

Windows Azure SDK for PHP

The Windows Azure SDK for PHP focuses on providing a means of interacting with several components of Windows Azure:

  • Blob storage is basically a large hard disk in the cloud. Blob Storage can host multiple files, or "blobs", located in different storage containers. A storage container is a logical group of files just like a logical disk drive or mount point on a regular computer.
  • Table storage is a relatively simple yet very scalable store for structured data. A table can contain different entities, identified by a partition key and row key. Each entity in a table can have different properties.
  • Queue service provides reliable, persistent messaging within and between services.
  • Diagnostics & logging, providing diagnostics information for applications running on Windows Azure.

All storage services are accessible via REST APIs and may be accessed from within a service running in Windows Azure or directly over the Internet from any application that can send an HTTP/HTTPS request and receive an HTTP/HTTPS response. The Windows Azure SDK provides an abstraction of these REST operations in the form of an easy-to-use PHP class library.

image

Figure 2:  Windows Azure SDK for PHP deployment scenarios

Windows Azure account structure

A Windows Azure storage account is structured as follows: every account includes blob storage, table storage and the queue service with specific HTTP(S) endpoints:

  • http://<account>.blob.core.windows.net/ <container>/<blob>
  • http:// <account>.table.core.windows.net/<table>
  • http:// <account>.queue.core.windows.net/<queue>

These endpoints are specific to the production Windows Azure environment. For development purposes, we suggest that you install the Windows Azure SDK (The Windows Azure SDK provides development simulations for both Windows Azure hosted services as well as storage services and can be downloaded from http://www.azure.com.). It provides a local Windows Azure version and gives you access to a local, simulated storage environment. The endpoints for this environment are the following:

  • http://127.0.0.1:10000/devstoreaccount1/<container>/ <blob>
  • http://127.0.0.1:10002/ devstoreaccount1/<table>
  • http://127.0.0.1:10001/ devstoreaccount1/<queue>

Access to the storage endpoints is granted based on an account key that you choose and a generated account key. For the development storage environment the following account is the default one:

Account name: devstoreaccount1
Account key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

http://<account>.blob.core.windows.net/ <container>/<blob>

http://<account>.queue.core.windows.net/ <queue>

http://<account>.table.core.windows.net/ <table>

image

Figure 3: Windows Azure storage account

 

Windows Azure SDK for PHP main classes

After downloading the Windows Azure SDK for PHP, all operations on storage accounts are executed through the Microsoft_WindowsAzure_Storage_* classes, where the following are available:

  • Microsoft_WindowsAzure_Storage_Blob
  • Microsoft_WindowsAzure_Storage_Table
  • Microsoft_WindowsAzure_Storage_Queue
  • Microsoft_WindowsAzure_Diagnostics_Manager

These classes should be instantiated either without any parameters which will connect to the development storage service or with a specific endpoint, account name and account key. The latter case is demonstrated in the code sample below:

/** Microsoft_WindowsAzure_Storage_Blob */

require_once 'Microsoft/WindowsAzure/Storage/Blob.php';

$storageClient = new Microsoft_WindowsAzure_Storage_Blob(

'blob.core.windows.net',

'mysampleaccount',
'0uSRZ6IFsuFq2UVEEby8vdPLlmEtlCDXJ1OUzFT5rCz4I6tq/K1SM02xNOcqFlqUoGMGw=='

);

 

Sample use cases

The blob, table and queue services provided with Windows Azure can be accessed using the Windows Azure SDK for PHP. The following are some sample use cases on leveraging one or more of these services for your PHP applications in conjunction with the Windows Azure SDK for PHP.

  • Offloading static content to blob storage and the content delivery network (CDN), optionally with a custom domain name
  • Protecting downloads using blob storage and shared access signatures
  • Reducing security risks by uploading user content to blob storage instead of your webserver
  • File versioning using blob snapshots
  • Backup location in blob storage
  • Using table storage as a non-relational database
  • Storing object data on table storage
  • Communicating between applications and application components through queue service
  • Guaranteed message delivery using the queue service
  • Configuring and monitoring diagnostics data for a Windows Azure deployment using the diagnostics API
  • Managing Windows Azure diagnostics remotely

Working with blob storage

Blob Storage stores sets of binary data. Blob storage offers the following three resources: the storage account, containers, and blobs. Within your storage account, containers provide a way to organize sets of blobs within your storage account.

Blob Storage is offered by Windows Azure as a REST API which is wrapped by the Windows Azure SDK for PHP in order to provide a native PHP interface to the storage account.

Blob storage features

image

Windows Azure blob storage and the Windows Azure SDK for PHP provide the following features:

  • List Containers - Lists all of the containers in the given storage account.
  • Create Container - Creates a new container in the given storage account.
  • Get Container Properties - Returns all properties and metadata on the container.
  • Get Container Metadata - Returns only user-defined metadata for the specified container.
  • Set Container Metadata - Sets metadata headers on the container.
  • Get Container ACL - Gets the access control list (ACL) and any container-level access policies for the container.
  • Set Container ACL - Sets the ACL and any container-level access policies for the container.
  • Delete Container - Deletes the container and any blobs that it contains.
  • List Blobs - Lists all of the blobs in the given container.
  • Put Blob - Creates a new blob or replaces an existing blob within a container.
  • Get Blob - Reads or downloads a blob from the system, including its metadata and properties.
  • Get Blob Properties - Returns all properties and metadata on the blob.
  • Set Blob Properties - Sets system properties defined for a blob.
  • Get Blob Metadata - Retrieves metadata headers on the blob.
  • Set Blob Metadata - Sets metadata headers on the blob.
  • Delete Blob - Deletes a blob.
  • Lease Blob - Establishes an exclusive one-minute write lock on a blob. To write to a locked blob, a client must provide a lease ID.
  • Snapshot Blob - Creates a snapshot of a blob.
  • Copy Blob - Copies a source blob to a destination blob within the same storage account.
  • Put Block - Creates a new block to be committed as part of a block blob.
  • Put Block List - Commits a blob by specifying the set of block IDs that comprise the block blob.
  • Get Block List - Retrieves the list of blocks that make up the block blob.
  • Put Page - Puts a range of pages into a page blob, or clears a range of pages from the blob.
  • Get Page Regions - Returns a list of active page ranges for a page blob. Active page ranges are those that have been populated with data.
  • Shared access signatures - Allow temporary access to a container or blob with different credentials
  • Register file stream wrapper - Allows PHP to use Windows Azure blob storage as a regular filesystem using standard file system functions like fopen, fread, and so on.


Working with table storage

image

 

The Table service offers structured storage in the form of tables.

Table Storage is offered by Windows Azure as a REST API which is wrapped by the Windows Azure SDK for PHP in order to provide a native PHP interface to the storage account.

 

Table storage features

Windows Azure table storage and the Windows Azure SDK for PHP provide the following features:

  • Query Tables - Enumerates the tables in a storage account.
  • Create Table - Creates a new table within a storage account.
  • Delete Table - Deletes a table from a storage account.
  • Query Entities - Queries data in a table.
  • Insert Entity - Inserts a new entity into a table.
  • Update Entity - Updates an existing entity within a table by replacing it.
  • Merge Entity - Updates an existing entity within a table by merging new property values into the entity.
  • Delete Entity - Deletes an entity within a table
  • Session handler - Store PHP session information in table storage in a transparent manner.
  • Table to object mapper - Automatically maps PHP objects to Windows Azure table storage and vice-versa.

Working with the queue service

image

 

The Queue service stores messages that may be read by any client who has access to the storage account.

A queue can contain an unlimited number of messages, each of which can be up to 8 KB in size. Messages are generally added to the end of the queue and retrieved from the front of the queue, although first in/first out (FIFO) behavior is not guaranteed. If you need to store messages larger than 8 KB, you can store message data as a blob or in a table and then store a reference to the data as a message in a queue.

Queue Storage is offered by Windows Azure as a REST API which is wrapped by the Windows Azure SDK for PHP in order to provide a native PHP interface to the storage account.

Queue service features

Windows Azure queue service and the Windows Azure SDK for PHP provide the following features:

  • List Queues - Lists all queues under the given account.
  • Create Queue - Creates a new queue under the given account.
  • Delete Queue - Deletes a queue.
  • Get Queue Metadata - Returns queue properties, including user-defined metadata.
  • Set Queue Metadata - Sets user-defined metadata on the queue.
  • Put Message - Adds a message to the queue.
  • Get Messages - Retrieves a message from the queue and makes it invisible to other consumers.
  • Peek Messages - Retrieves a message from the front of the queue, without changing the message visibility.
  • Delete Message - Deletes a specified message from the queue.
  • Clear Messages - Clears all messages from the queue.

 

 

Working with diagnostics & logging

Windows Azure Diagnostics enables you to collect diagnostic data from a service running in Windows Azure. It can be used for tasks like debugging and troubleshooting, measuring performance, monitoring resource usage, traffic analysis, capacity planning, and auditing. Once collected, diagnostic data can be transferred to a Windows Azure storage account for persistence. Transfers can either be scheduled or on-demand.

You can configure Windows Azure Diagnostics from code running within a role. You can also configure it remotely from an application running outside of the Windows Azure; for example, you can manage Windows Azure Diagnostics from a custom dashboard application running on-premise. By managing Windows Azure Diagnostics remotely, you can start your service with an initial diagnostic configuration, and then tweak that configuration from code running outside of your service, without having to upgrade your service.

More information on which logs, performance counters, crash dumps, etc. can be monitored can be found on the corresponding MSDN web page.

Diagnostics features

Windows Azure diagnostics and the Windows Azure SDK for PHP provide the following features:

  • Configure diagnostics data sources:
    • Windows Azure logs
    • IIS 7.0 logs
    • Windows Diagnostic infrastructure logs
    • Failed Request logs
    • Windows Event logs
    • Crash dumps
    • Custom error logs
  • Configure transfer intervals
  • Configure quotas for diagnostics data

Additional Resources

  • WindowsAzure for PHP - Articles, tutorials, downloads, and more
PHP Software development kit azure Database Relational database Web Service application Container

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Detecting Network Anomalies Using Apache Spark
  • Asynchronous Messaging Service
  • How Chat GPT-3 Changed the Life of Young DevOps Engineers
  • Introduction Garbage Collection Java

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: