Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP in Windows Azure Cloud – hosting scalable and reliable solutions

fwdays
October 18, 2013

PHP in Windows Azure Cloud – hosting scalable and reliable solutions

fwdays

October 18, 2013
Tweet

More Decks by fwdays

Other Decks in Programming

Transcript

  1. PHP in Windows Azure Cloud – hosting scalable and reliable

    solutions Viktor Tsykunov Developers and Platform Evangelism Lead Microsoft Ukraine [email protected]
  2. CDN Connect Load Balancer Web Role Worker Role Hosted Service

    Business Analytics Database SQL Azure Traffic Manager Networking Caching Identity HD Insight Mobile Services Blob Drive Table Storage Queue Service Bus Fabric Controller Elastic Data Sync
  3. PS C:\>New-AzureServiceProject myProject PS C:\myProject> Add-AzurePHPWebRole roleName PS C:\myProject> Get-AzureServiceProjectRoleRuntime

    Runtime Version PackageUri IsDefault ------- ------- ---------- --------- Node 0.6.17 http://nodertncu.blob.core... False Node 0.6.20 http://nodertncu.blob.core... True Node 0.8.4 http://nodertncu.blob.core... False IISNode 0.1.21 http://nodertncu.blob.core... True Cache 1.8.0 http://nodertncu.blob.core... True PHP 5.3.17 http://nodertncu.blob.core... True PHP 5.4.0 http://nodertncu.blob.core... False PS C:\myProject> Set-AzureServiceProjectRole roleName php 5.4.0
  4. PS C:\MyProject> Start-AzureEmulator Creating local package... Starting Emulator... Role is

    running at http://127.0.0.1:81 Started PS C:\MyProject> Stop-AzureEmulator PS C:\MyProject> Publish-AzureServiceProject -Subscription MyTestSubscription -StorageAccountName MyTestStorageAccountName Publishing to Windows Azure. This may take several minutes... 6:15:58 PM - Preparing deployment for MyService with Subscription ID: 0807028c-e0a5-4773-82e3- 8cae71dd5702... 6:16:04 PM - Connecting... 6:16:07 PM - Creating... 6:16:09 PM - Created hosted service 'MyService'. 6:16:09 PM - Verifying storage account 'myservice'... 6:18:14 PM - Uploading Package... 6:20:41 PM - Created Deployment ID: 7ce799c2023a4ae9b346b970045cd14c. 6:20:41 PM - Starting... 6:20:41 PM - Initializing... 6:20:55 PM - Instance WebRole1_IN_0 of role WebRole1 is creating the virtual machine. 6:24:26 PM - Instance WebRole1_IN_0 of role WebRole1 is busy. 6:25:42 PM - Instance WebRole1_IN_0 of role WebRole1 is ready. 6:25:43 PM - Created Website URL: http://MyService.cloudapp.net. 6:25:43 PM - Complete.
  5. // include_path option for setting, choose library folder for Windows

    Azure SDK for PHP set_include_path(ini_get('include_path') . PATH_SEPARATOR . './library/'); // Windows Azure SDK for PHP read library require_once 'Microsoft/AutoLoader.php'; // Constant define('DEV', false); // Check develop fabric define('STORAGE_ACCOUNT', 'storage account'); // Created storage account define('STORAGE_KEY', 'storage accoune key'); // Created storage account key define('CONTAINER_NAME', 'sample'); // name of container // Create instance if (DEV) { // Connect storage emulator $blobClient = new Microsoft_WindowsAzure_Storage_Blob(); } else { // Windows Azure Storage $blobClient = new Microsoft_WindowsAzure_Storage_Blob( Microsoft_WindowsAzure_Storage::URL_CLOUD_BLOB, STORAGE_ACCOUNT, STORAGE_KEY ); }
  6. // Confirm existence of container that chosen by contaierExists method,

    if not, create new conteiner by createContainer method. if (!$blobClient->containerExists(CONTAINER_NAME)) { $result = $blobClient->createContainer(CONTAINER_NAME); echo $result->Name . “created \r\n"; } else { echo CONTAINER_NAME . “exist \r\n"; } // Confirm existence of container that chosen by contaierExists method, if not, create new conteiner by createContainer method. $blobClient->createContainerIfNotExists(CONTAINER_NAME); if ($blobClient->containerExists(CONTAINER_NAME)) { $result = $blobClient->deleteContainer(CONTAINER_NAME); echo $result->Name . “Deleted \r\n"; } else { echo CONTAINER_NAME . “Not existed \r\n"; } Delete container Delete exist container
  7. $result = $blobClient->listContainers(); foreach ($result as $container) { echo $container->Name."\r\n";

    } if (file_exists('./sample.jpg')) { $result = $blobClient->putBlob(CONTAINER_NAME, 'sample.jpg', './sample.jpg', null, null, array('x-ms-blob-content-type'=>'image/jpeg')); echo ‘name of uploaded blob: ' . $result->Name."\r\n"; }
  8. $blobClient->getBlob(CONTAINER_NAME, 'sample.jpg', './sample-download.jpg'); // Copy from sample.jpg to sample-copy.jpg (in

    same container) $result = $blobClient->copyBlob(CONTAINER_NAME, 'sample.jpg', CONTAINER_NAME, 'sample-copy.jpg'); echo ‘copied Blob: ' . $result->Name; // Copy from sample.jpg to sample.jpg (in different container) $blobClient->createContainerIfNotExists(CONTAINER_NAME."2nd"); $result = $blobClient->copyBlob(CONTAINER_NAME, 'sample.jpg', CONTAINER_NAME."2nd", 'sample.jpg'); echo ‘Copied Blob: ' . $result->Name;
  9. // To Blob if ($blobClient->blobExists(CONTAINER_NAME, "sample.jpg")) { $result = $blobClient->deleteBlob(CONTAINER_NAME,

    "sample.jpg"); echo “Deleted Blob:" . $result->Name; } // To get a list of Blob begin with sample $result = $blobClient->listBlobs(CONTAINER_NAME, "sample"); foreach ($result as $blob) { echo $blob->Name."\r\n"; }