#PHP-Queue Windows Azure Queue Demo
Demo app for Windows Azure Service Bus Queue backend.
Sample code from my presentation at The Singapore Xmas Azure Workshop on 20 Dec 2012. Here are the presentation slides.
##Setup Instructions
###Pre-requisites
-
Register for a Windows Azure account. You can use the free 90 days trial here.
-
Create a Windows Azure website (tutorial here).
-
Create a Windows Azure Service Bus Namespace (tutorial here).
-
Create a Windows Azure Blob Storage Account (tutorial here).
-
Create 2 new Containers:
photosupload
andphotoscdn
. -
Download the sample code.
$ git clone git://github.com/miccheng/PHP-Queue-Windows-Azure-Queue-Demo.git
-
Download and install Composer
$ curl -s "http://getcomposer.org/installer" | php
-
Download the Windows Azure SDK & PHP-Queue via Composer.
$ php composer.phar install
###Environment Variables
You have to prepare 2 connection strings:
queue_connection_string
- For connecting to your Service Bus Namespace.wa_blob_connection_string
- For connecting to your Blob Storage Account.
Refer to the Windows Azure tutorials above to find out how to get these connection string/credentials
####Adding to Windows Azure Website
- Login to the Windows Azure Management Portal
- Click on the Website that you created.
- Click on "Configure"
- Scroll down to "app settings" and add your connection strings.
-
In console, type:
$ export queue_connection_string='Endpoint=<EndpointURL>;SharedSecretIssuer=owner;SharedSecretValue=<SharedSecret>' $ export wa_blob_connection_string='DefaultEndpointsProtocol=https;AccountName=<YourNameSpace>;AccountKey=<AccountKey>'
-
To check that your have the info in your environemnt:
$ export $queue_connection_string
It should print out your connection string.
-
To make sure these environment variables are added whenever you boot up or SSH into your machine, edit the
.bash_profile
file in user's home directory.$ vim ~/.bash_profile
Add:
export queue_connection_string='Endpoint=<EndpointURL>;SharedSecretIssuer=owner;SharedSecretValue=<SharedSecret>' export wa_blob_connection_string='DefaultEndpointsProtocol=https;AccountName=<YourNameSpace>;AccountKey=<AccountKey>'
OR use the env.php
file
-
cd
tobin
folder. -
Copy
env.sample.php
toenv.php
. -
Edit that file and fill in your connection string info for your Windows Azure Service Bus Namespace and Windows Azure Blob Storage account.
<?php # Rename this file to env.php and place in the same folder as cli.php and daemon.php putenv("queue_connection_string='Endpoint=https://yournamespace.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=XXXXX'"); putenv("wa_blob_connection_string='DefaultEndpointsProtocol=https;AccountName=youraccount;AccountKey=XXXXXX'");
-
First, publish the sample code to your Windows Azure Website
$ git add remote azure https://<username>@<WindowsAzureGitRepo> $ git push azure master
-
REST interface
$ curl -XPOST http://<yourwebsitename>.azurewebsites.net/Noob/ -d "var1=foo&var2=bar" $ curl -XPOST http://<yourwebsitename>.azurewebsites.net/Noob/?REQUEST_METHOD=PUT -d "t=meh"
-
CLI interface
$ php cli.php Noob add --data '{"name":"Dino Bing"}' $ php cli.php Noob work
-
Visit the gallery website:
http://<yourwebsitename>.azurewebsites.net/gallery/
-
Click on "Upload" to upload a photo.
-
Run the Job.
$ php cli.php Photos work
-
Go back to the Gallery page and refresh.
-
Your new photo should appear.
-
Start a Windows Azure Virtual Machine (use the CentOS 6.2 linux distro).
-
SSH into your VM.
-
Create a new file
install.sh
and use these contents.#!/bin/sh sudo yum install -y screen git php php-gd php-pear php-process curl -s https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer git clone git://github.com/miccheng/PHP-Queue-Windows-Azure-Queue-Demo.git cd PHP-Queue-Windows-Azure-Queue-Demo composer install
-
Run the script to install the required software to run the daemon. The script would also checkout a copy of the sample code into your current folder.
$ sh install.sh
-
cd
to thebin
directory. -
Start the daemon:
$ php daemon.php start
-
To stop the daemon:
$ php daemon.php stop