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

PHP in Windows Azure Cloud – hosting scalable and reliable solutions

Dd3f18c87b851137000c7427d7bd5d32?s=47 fwdays
October 18, 2013

PHP in Windows Azure Cloud – hosting scalable and reliable solutions

Dd3f18c87b851137000c7427d7bd5d32?s=128

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 Viktor.Tsykunov@microsoft.com
  2. None
  3. None
  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  10. None
  11. None
  12. None
  13. None
  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. None
  22. 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
  23. • • • • • 23

  24. • • • • 24

  25. • • • 25

  26. • • • 26

  27. None
  28. 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
  29. 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.
  30. None
  31. None
  32. CloudBerry Explorer

  33. None
  34. // 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 ); }
  35. // 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
  36. $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"; }
  37. $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;
  38. // 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"; }
  39. None