require_once 'Microsoft/AutoLoader.php';
// Setup some constant configuration values
define('DEV', true);
define('STORAGE_ACCOUNT', '<endpoint of your storage account>');
define('STORAGE_KEY', '<storage account key>');
define('QUEUE_GUESTBOOK', 'guestbook');
// Setup the connection
if (DEV) {
    // Connect to local development storage
    $queue = new Microsoft_WindowsAzure_Storage_Queue();
} else {
    // Connect to Windows Azure Storage in the cloud
    $queue = new Microsoft_WindowsAzure_Storage_Queue('queue.core.windows.net', STORAGE_ACCOUNT, STORAGE_KEY);
}
// Ensure the queue exists
$queue->createQueueIfNotExists(QUEUE_GUESTBOOK);
// If the user submitted something put it into the queue storage
// NOTE: Inputs are not cleaned for example purposes
if (isset($_POST['NameTextBox']) && isset($_POST['MessageTextBox'])) {
    $obj = array('GuestName' => $_POST['NameTextBox'], 'Message' => $_POST['MessageTextBox']);
    $obj = serialize($obj);
    $queue->putMessage(QUEUE_GUESTBOOK, $obj);
}
// User wishes to delete something
if (isset($_GET['process'])) {
    $msgs = $queue->getMessages(QUEUE_GUESTBOOK, 32);
    // 32 is the max that can be retrieve at once
    foreach ($msgs as $m) {
        $queue->deleteMessage(QUEUE_GUESTBOOK, $m);
    }
}