function InitializeStorage() { if (USE_DEV_EMULATOR) { //Connect to the Storage Emulator $tableClient = new Microsoft_WindowsAzure_Storage_Table(); $blobClient = new Microsoft_WindowsAzure_Storage_Blob(); $queueClient = new Microsoft_WindowsAzure_Storage_Queue(); } else { //Connect to Azure storage $tableClient = new Microsoft_WindowsAzure_Storage_Table(AZURE_TABLES_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); $blobClient = new Microsoft_WindowsAzure_Storage_Blob(AZURE_BLOBS_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); $queueClient = new Microsoft_WindowsAzure_Storage_Table(AZURE_QUEUES_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); } //Create a table to store GuestBook Entries if it doesn't exist if (!$tableClient->tableExists(GB_TABLE_NAME)) { $result = $tableClient->createTable(GB_TABLE_NAME); } //Validate the blob container name if ($blobClient->isValidContainerName(GB_BLOB_CONTAINER)) { if (!$blobClient->containerExists(GB_BLOB_CONTAINER)) { //create it if it doesn't exist $result = $blobClient->createContainer(GB_BLOB_CONTAINER); //Make it public $blobClient->setContainerAcl(GB_BLOB_CONTAINER, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC); $blobClient->registerStreamWrapper(); } } //Create a queue to send thumbnail jobs to a worker process if it doesn't exist $queue = $queueClient->createQueueIfNotExists(GB_QUEUE_NAME); return array($tableClient, $blobClient, $queueClient); }
protected function createStorageInstance() { $storageClient = null; if (TESTS_TABLE_RUNONPROD) { $storageClient = new Microsoft_WindowsAzure_Storage_Table(TESTS_TABLE_HOST_PROD, TESTS_STORAGE_ACCOUNT_PROD, TESTS_STORAGE_KEY_PROD, false, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250)); } else { $storageClient = new Microsoft_WindowsAzure_Storage_Table(TESTS_TABLE_HOST_DEV, TESTS_STORAGE_ACCOUNT_DEV, TESTS_STORAGE_KEY_DEV, true, Microsoft_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 250)); } if (TESTS_STORAGE_USEPROXY) { $storageClient->setProxy(TESTS_STORAGE_USEPROXY, TESTS_STORAGE_PROXY, TESTS_STORAGE_PROXY_PORT, TESTS_STORAGE_PROXY_CREDENTIALS); } return $storageClient; }
function DisplayGuestBookTable() { //Initialize Table Storage if (USE_DEV_EMULATOR) { //Connect to the Storage Emulator $tableClient = new Microsoft_WindowsAzure_Storage_Table(); } else { //Connect to Azure storage $tableClient = new Microsoft_WindowsAzure_Storage_Table(AZURE_TABLES_URL, AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY); } //Create a table to store GuestBook Entries if it doesn't exist if (!$tableClient->tableExists(GB_TABLE_NAME)) { $result = $tableClient->createTable(GB_TABLE_NAME); } //Construct a query that will look for guest book entries with the current date. $nowDT = new DateTime('now', new DateTimeZone('UTC')); $partitionKey = $nowDT->format("mdY"); $query = "PartitionKey eq '" . $partitionKey . "'"; echo '<table id="gbEntryTable" cellspacing="0" border="0" style="border-collapse:collapse;">'; $entries = $tableClient->retrieveEntities("GuestBookEntry", $query, "GuestBookEntry"); foreach ($entries as $entry) { echo '<tr><td>'; echo '<div class="signature">'; echo ' <div class="signatureImage">'; echo ' <a href="' . $entry->PhotoUrl . '" target="_blank">'; echo ' <img src="' . $entry->ThumbnailUrl . '"'; echo ' alt="' . $entry->GuestName . '" />'; echo ' </a>'; echo ' </div>'; echo ' <div class="signatureDescription">'; echo ' <div class="signatureName">'; echo $entry->GuestName; echo ' </div>'; echo ' <div class="signatureSays">'; echo 'says'; echo ' </div>'; echo ' <div class="signatureDate">'; echo $entry->getTimestamp()->format('Y-m-d H:i:s'); echo ' </div>'; echo ' <div class="signatureMessage">'; echo '"' . $entry->Message . '"'; echo ' </div>'; echo ' </div>'; echo '</div>'; echo '</td></tr>'; } echo '</table>'; }
/** * Garbage collector * * @param int $lifeTime Session maximal lifetime * @see session.gc_divisor 100 * @see session.gc_maxlifetime 1440 * @see session.gc_probability 1 * @usage Execution rate 1/100 (session.gc_probability/session.gc_divisor) * @return boolean */ public function gc($lifeTime) { if ($this->_storageType == self::STORAGE_TYPE_TABLE) { // In table storage try { $result = $this->_storage->retrieveEntities($this->_sessionContainer, 'PartitionKey eq \'' . $this->_sessionContainerPartition . '\' and sessionExpires lt ' . (time() - $lifeTime)); foreach ($result as $sessionRecord) { $this->_storage->deleteEntity($this->_sessionContainer, $sessionRecord); } return true; } catch (Microsoft_WindowsAzure_exception $ex) { return false; } } else { if ($this->_storageType == self::STORAGE_TYPE_BLOB) { // In blob storage try { $result = $this->_storage->listBlobs($this->_sessionContainer, $this->_sessionContainerPartition, '', null, null, 'metadata'); foreach ($result as $sessionRecord) { if ($sessionRecord->Metadata['sessionexpires'] < time() - $lifeTime) { $this->_storage->deleteBlob($this->_sessionContainer, $sessionRecord->Name); } } return true; } catch (Microsoft_WindowsAzure_exception $ex) { return false; } } } }
/** * Garbage collector * * @param int $lifeTime Session maximal lifetime * @see session.gc_divisor 100 * @see session.gc_maxlifetime 1440 * @see session.gc_probability 1 * @usage Execution rate 1/100 (session.gc_probability/session.gc_divisor) * @return boolean */ public function gc($lifeTime) { try { $result = $this->_tableStorage->retrieveEntities($this->_sessionTable, 'PartitionKey eq \'' . $this->_sessionTablePartition . '\' and sessionExpires lt ' . (time() - $lifeTime)); foreach ($result as $sessionRecord) { $this->_tableStorage->deleteEntity($this->_sessionTable, $sessionRecord); } return true; } catch (Microsoft_WindowsAzure_exception $ex) { return false; } }
* if you wish to run the sample on Windows Azure you must change * DEV to false and set your account and keys appropriately */ define('DEV', true); define('STORAGE_ACCOUNT', '<endpoint of your storage account>'); define('STORAGE_KEY', '<storage account key>'); define('TABLE_GUESTBOOK', 'guestbook'); define('BLOB_GUESTBOOK', 'guestbook'); // Setup the connection if (DEV) { // Connect to local development storage $table = new Microsoft_WindowsAzure_Storage_Table(); $blob = new Microsoft_WindowsAzure_Storage_Blob(); } else { // Connect to Windows Azure Storage in the cloud $table = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net', STORAGE_ACCOUNT, STORAGE_KEY); $blob = new Microsoft_WindowsAzure_Storage_Blob('blob.core.windows.net', STORAGE_ACCOUNT, STORAGE_KEY); } // Ensure the table exists $table->createTableIfNotExists(TABLE_GUESTBOOK); // Ensure the blob container exists $blob->createcontainerIfNotExists(BLOB_GUESTBOOK); // Set ACL $blob->setContainerAcl(BLOB_GUESTBOOK, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER); // If the user submitted something put it into the table storage // NOTE: Inputs are not cleaned for example purposes if (isset($_POST['NameTextBox']) && isset($_POST['MessageTextBox'])) { $g = new GuestBookEntry(); $image = $blob->putBlob(BLOB_GUESTBOOK, $_FILES['Image']['name'], $_FILES['Image']['tmp_name']); $g->GuestName = $_POST['NameTextBox']; $g->Message = $_POST['MessageTextBox'];
<?php require_once 'Microsoft/WindowsAzure/Storage/Table.php'; $storageClient = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net', 'myaccount', 'myauthkey'); $entities = $storageClient->storageClient->retrieveEntities('testtable', $storageClient->select()->from($tableName)->where('Name eq ?', 'Mario')->andWhere('PartitionKey eq ?', 'partition1'), 'SampleEntity'); foreach ($entities as $entity) { echo 'Nome: ' . $entity->Name . "\n"; }
<?php require_once 'Microsoft/WindowsAzure/Storage/Table.php'; $storageClient = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net', 'myaccount', 'myauthkey'); $result = $storageClient->createTable('testtable'); echo 'Nuova tabella creata: ' . $result->Name;
<?php require_once 'Microsoft/WindowsAzure/Storage/Table.php'; $entity = new SampleEntity('partition1', 'row1'); $entity->FullName = "Mario"; $entity->Age = 35; $entity->Visible = true; $storageClient = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net', 'myaccount', 'myauthkey'); $result = $storageClient->insertEntity('testtable', $entity); echo 'Timestamp: ' . $result->getTimestamp() . "\n"; echo 'Etag: ' . $result->getEtag() . "\n";