Open a window, see the clouds - php|tek 2011

  • 6,104 views
Uploaded on

Is your application ready to take off into the cloud? What does this mean? What do you need to worry about? What frameworks and tools do you need to look at and what new concepts do you need to put in …

Is your application ready to take off into the cloud? What does this mean? What do you need to worry about? What frameworks and tools do you need to look at and what new concepts do you need to put in your PHP toolbox to prepare? Get acquainted with Microsoft Azure's platform and features, and discover what tools and frameworks are ready to benefit from this new paradigm.

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
6,104
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
21
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Open a Window, see the clouds Rafael Dohms photo credit: Denis GrzeticWednesday, May 25, 2011
  • 2. Rafael Dohms photo credit: Eli White PHP Evangelist and ZCE in Brazil and a very active member of the PHP Community. He helped found two PHP User Groups over the years and currently shares the lead of PHPSP. Developer, gamer and lover of code he also hosts Brazil’s first PHP Podcast: PHPSPCast.  Currently he works for MIH SWAT Team, a group of experts that provides technical knowledge to the MIH group as well as working on R&D in search of the new and exciting niches of the web. His role as a Senior PHP Developer is to code, train and aid other companies and to have fun doing so.Wednesday, May 25, 2011
  • 3. PEEKING OUT THE WINDOW • What is the Cloud? • Why choose the Cloud? • Let’s take a look at Windows Azure • How does that affect my code?Wednesday, May 25, 2011
  • 4. WHAT IS THE CLOUD? not just another buzzword bingo wordWednesday, May 25, 2011
  • 5. REGULAR HOSTING • Shared account, VPS or Local Machine • One machine, one place • Pay by monthWednesday, May 25, 2011
  • 6. Self REGULAR HOSTING • Shared account, VPS or Local Machine • One machine, one place • Pay by monthWednesday, May 25, 2011
  • 7. CLOUD COMPUTING • Less “physical attachment” • One or multiple machines or “instances” • Geologically spread • Pay per hour/usage/data • “abstraction” of resources • 3 Flavors: IaaS, PaaS, SaaSWednesday, May 25, 2011
  • 8. Data Application Software Operating System Hardware/NetworkWednesday, May 25, 2011
  • 9. Storing Data Sharing Deploying Application Developing MySQL Software Apache Configuring Operating System Upgrading Cooling Hardware/Network CablingWednesday, May 25, 2011
  • 10. IaaS a Service” “Infrastructure as Data Application Software Operating System Hardware/NetworkWednesday, May 25, 2011
  • 11. IaaS a Service” “Infrastructure as Data Application Software Operating System you them Hardware/NetworkWednesday, May 25, 2011
  • 12. PaaS “Platform as a Service” Data Application Software Operating System Hardware/NetworkWednesday, May 25, 2011
  • 13. PaaS “Platform as a Service” Data Application you them Software Operating System Hardware/NetworkWednesday, May 25, 2011
  • 14. SaaS “Software as a Service” Data Application Software Operating System Hardware/NetworkWednesday, May 25, 2011
  • 15. SaaS “Software as a Service” Data you them Application Software Operating System Hardware/NetworkWednesday, May 25, 2011
  • 16. X WHY CHOOSE THE CLOUD? What are the advantages of using the cloud?Wednesday, May 25, 2011
  • 17. traffic time THE UTILITY MODELWednesday, May 25, 2011
  • 18. traffic time THE UTILITY MODELWednesday, May 25, 2011
  • 19. traffic peak time THE UTILITY MODELWednesday, May 25, 2011
  • 20. traffic peak time THE UTILITY MODELWednesday, May 25, 2011
  • 21. traffic peak time THE UTILITY MODELWednesday, May 25, 2011
  • 22. IaaS Paas SaaS costs server managment. software management product deployWednesday, May 25, 2011
  • 23. AVAILABILITYWednesday, May 25, 2011
  • 24. AVAILABILITYWednesday, May 25, 2011
  • 25. AVAILABILITYWednesday, May 25, 2011
  • 26. SCALABILITY Stateless Compute + Durable StorageWednesday, May 25, 2011
  • 27. SCALABILITY Stateless Compute + Durable StorageWednesday, May 25, 2011
  • 28. LET’S LOOK INSIDEWednesday, May 25, 2011
  • 29. Windows Azure Overview Fabric Compute StorageWednesday, May 25, 2011
  • 30. Fabric Middleware, used for developing, deploying and managing your applications AppFabric developerWednesday, May 25, 2011
  • 31. Fabric Compute StorageWednesday, May 25, 2011
  • 32. Compute Web Role Worker Role VM Role Windows Server Web application Background 2008 instance that running on top of processing can be loaded on IIS demandWednesday, May 25, 2011
  • 33. Fabric Compute StorageWednesday, May 25, 2011
  • 34. Cached version of CDN any resource in storage with a URI Storage Data Storage Table Storage Blob Storage SQL Azure Queue Text and binary Compatible with Messaging between Structured Storage data SQL Server Web and WorkerWednesday, May 25, 2011
  • 35. UP & RUNNING for Development and Deployment • Requisites: • IIS7 Tools • Azure SDK (install DevAppFabric, the azure emulator) • Command Line Tools • Command line tools for PHPWednesday, May 25, 2011
  • 36. BASIC TOOLSET • Command Line tools for PHP • Packages applicationand runs in emulator, with simulated compute and storage. • Azure Tools for Eclipse • Makes most processes a click-through process and gives you a nice IDEWednesday, May 25, 2011
  • 37. Developer Environment Azure Emulator Code (Dev fabric) Packaging tools (command line or eclipse) Package + Service Configuration Azure Window Azure (AppFabric) SQLAzure StorageWednesday, May 25, 2011
  • 38. Developer Environment Azure Emulator Code (Dev fabric) PHP Packaging tools (command line or eclipse) Package + Service Configuration Azure Window Azure (AppFabric) SQLAzure StorageWednesday, May 25, 2011
  • 39. Developer Environment Azure Emulator Code (Dev fabric) PHP Packaging tools (command line or eclipse) Package + Service Configuration Azure Window Azure (AppFabric) SQLAzure StorageWednesday, May 25, 2011
  • 40. Developer Environment Azure Emulator Code (Dev fabric) php package.php PHP --project="twitter-azure" Packaging tools --target="c:azure-build" (command line or eclipse) --source="C:twitter-azure" Package + Service --defaultDoc="public/index.php" Configuration --phpRuntime="C:Program Files (x86)PHPv5.3" --cleanRebuild --runDevFabric Azure Window Azure (AppFabric) SQLAzure StorageWednesday, May 25, 2011
  • 41. Developer Environment Azure Emulator Code (Dev fabric) PHP Packaging tools (command line or eclipse) Package + Service Configuration Azure Window Azure (AppFabric) SQLAzure StorageWednesday, May 25, 2011
  • 42. THE GOOD • REST APIs • Storage • Diagnostics • Relational DB: SQL Azure • Role ArchitectureWednesday, May 25, 2011
  • 43. THE BAD • Windows-only Management • No Azure Emulator for non-Windows OS • No Packaging Command Line tools for non-Windows OSWednesday, May 25, 2011
  • 44. HOW DOES THAT AFFECT CODE? What tools can we use and how should we design our appsWednesday, May 25, 2011
  • 45. WHAT DO I WORRY ABOUT?Wednesday, May 25, 2011
  • 46. WHAT DO I WORRY ABOUT? CodeWednesday, May 25, 2011
  • 47. WHAT DO I WORRY ABOUT? Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 48. WHAT DO I WORRY ABOUT? Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 49. WHAT DO I WORRY ABOUT? Scaling Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 50. WHAT DO I WORRY ABOUT? Scaling No Local Storage Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 51. WHAT DO I WORRY ABOUT? Scaling No Local Storage Session sharing Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 52. WHAT DO I WORRY ABOUT? Scaling No Local Storage Session sharing Worker Roles Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 53. WHAT DO I WORRY ABOUT? Scaling No Local Storage Session sharing Worker Roles Queues Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 54. WHAT DO I WORRY ABOUT? Storage Scaling No Local Storage Session sharing Worker Roles Queues Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 55. WHAT DO I WORRY ABOUT? What kind? Storage Scaling No Local Storage Session sharing Worker Roles Queues Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 56. WHAT DO I WORRY ABOUT? Table / Blob What kind? Storage Scaling No Local Storage Session sharing Worker Roles Queues Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 57. WHAT DO I WORRY ABOUT? Table / Blob Framework or PHP SDK What kind? Storage Scaling No Local Storage Session sharing Worker Roles Queues Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 58. WHAT DO I WORRY ABOUT? Table / Blob Framework or PHP SDK What kind? Relational Database Storage Scaling No Local Storage Session sharing Worker Roles Queues Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 59. WHAT DO I WORRY ABOUT? Table / Blob Framework or PHP SDK What kind? Relational Migrate to SQL Azure Database Storage Scaling No Local Storage Session sharing Worker Roles Queues Architecture Code PHP on IIS/WindowsWednesday, May 25, 2011
  • 60. AZURE-READY FRAMEWORKSWednesday, May 25, 2011
  • 61. WHAT MAKES IT COMPATIBLE? Code Does it run on PHP on Windows? Tools Does it have API Handlers? Database Does it offer MS SQL Compatibility?Wednesday, May 25, 2011
  • 62. Tools • Blobs, Tables and Queues (CRUD operations) • Helper Classes for HTTP transport, AuthN/AuthZ, REST and Error Management • Manageability, Instrumentation and Logging support Database • Not tested, but should work well.Wednesday, May 25, 2011
  • 63. Database • MS-SQL Drivers* are compatible with SQLAzure * Using pdo_sql_server, possibly pdo_dblib Powered by Doctrine:Wednesday, May 25, 2011
  • 64. • PHP code runs normally, in Azure so any framework will work. • You will need other tools to communicate with resources like: DB, Queue, etc... • These have been tested!Wednesday, May 25, 2011
  • 65. AZURE PHP SDK • Services: • Blob Storage • Table Storage • Queue Storage • Diagnostic Tools • Compatible with PHP 5+Wednesday, May 25, 2011
  • 66. GOING OUT THE WINDOW Sample migration to the cloud • Sample Application: “Twitter RT Calculator” • Objective: Analyse your latest tweets that were ReTweeted, and calculate stats based on locations and words. • Show how to migrate: • Database: MySQL > SQLAzure • Move processing into a worker role using the QueueWednesday, May 25, 2011
  • 67. GOING OUT THE WINDOW Sample migration to the cloud • Sample Application: “Twitter RT Calculator” • Objective: Analyse your latest tweets that were ReTweeted, and calculate stats based on locations and words. • Show how to migrate: • Database: MySQL > SQLAzure • Move processing into a worker role using the QueueWednesday, May 25, 2011
  • 68. Twitter OAuth Wait for it...Wednesday, May 25, 2011
  • 69. Twitter OAuth Wait for it...Wednesday, May 25, 2011
  • 70. Twitter OAuth Wait for it...Wednesday, May 25, 2011
  • 71. Twitter OAuth Wait for it... MySQLWednesday, May 25, 2011
  • 72. Twitter OAuth Wait for it... MySQL ResultsWednesday, May 25, 2011
  • 73. Twitter OAuth Wait for it... MySQL ResultsWednesday, May 25, 2011
  • 74. Twitter OAuth Wait for it... MySQL ResultsWednesday, May 25, 2011
  • 75. Twitter OAuth Don’t call me, i’ll call youWednesday, May 25, 2011
  • 76. Twitter OAuth Queue Don’t call me, i’ll call youWednesday, May 25, 2011
  • 77. Twitter OAuth Queue Don’t call me, i’ll call you WorkerWednesday, May 25, 2011
  • 78. Twitter OAuth Queue Don’t call me, i’ll call you WorkerWednesday, May 25, 2011
  • 79. Twitter OAuth Queue Don’t call me, i’ll call you WorkerWednesday, May 25, 2011
  • 80. Twitter OAuth Queue Don’t call me, i’ll call you Worker SQLAzureWednesday, May 25, 2011
  • 81. Twitter OAuth Queue Don’t call me, i’ll call you Worker SQLAzureWednesday, May 25, 2011
  • 82. Twitter OAuth Queue Don’t call me, i’ll call you Worker Results SQLAzureWednesday, May 25, 2011
  • 83. Twitter OAuth Queue Don’t call me, i’ll call you Worker Worker Worker Worker Worker Worker Worker Worker Worker Worker Worker Results SQLAzureWednesday, May 25, 2011
  • 84. USING SQLAZURE PDO MSSQL Driver doctrine.dbal.connection_options: driver: pdo_sqlsrv dbname: twitter-sample-app host: pl69qjwy8k.database.windows.net port: 1433 user: rdohmsDemo@pl69qjwy8k password: *password*Wednesday, May 25, 2011
  • 85. LINE THEM UP IN THE QUEUE //Add user to our Queue $qItem = new stdClass(); $qItem->twitter_handle = $twitterInfo->screen_name; $qManager = new AzureQueue($this->getApp()->getConfig(azure)); $qManager->addToQueue($qItem);Wednesday, May 25, 2011
  • 86. LINE THEM UP IN THE QUEUE //Add user to our Queue $qItem = new stdClass(); $qItem->twitter_handle = $twitterInfo->screen_name; $qManager = new AzureQueue($this->getApp()->getConfig(azure)); $qManager->addToQueue($qItem); $this->client = new Zend_Service_WindowsAzure_Storage_Queue( $qConfig[host], $qConfig[accountName], $qConfig[accountKey] ); $this->queue = $this->getQueueInstance($queueName); __contruct()Wednesday, May 25, 2011
  • 87. LINE THEM UP IN THE QUEUE //Add user to our Queue $qItem = new stdClass(); $qItem->twitter_handle = $twitterInfo->screen_name; $qManager = new AzureQueue($this->getApp()->getConfig(azure)); $qManager->addToQueue($qItem); $this->client = new Zend_Service_WindowsAzure_Storage_Queue( $qConfig[host], $qConfig[accountName], $qConfig[accountKey] ); $this->queue = $this->getQueueInstance($queueName); __contruct() public function addToQueue($item) { $this->client->putMessage($this->queue->name, serialize($item)); }Wednesday, May 25, 2011
  • 88. while (true){ try{ $this->logAction("Checking for messages..."); FIRST COME, //Read Queue $qMessage = $qManager->getMessage(); //If no message, sleep for 3 seconds and try again FIRST SERVED if ($qMessage === null){ $this->logAction("No pending messages..."); sleep(3); continue; } //Retrieve User {... doctrine query for stored twitter handle ...} //Clear Message $this->logAction("Removing message form queue..."); $qManager->deleteMessage($qMessage); //Process User $this->processUser($user); //Warn User $this->sendWarning($user); } catch (Exception $e) { $this->logAction("Exception found:" .$e->getMessage } $this->logAction("Initiating sleep for next loop."); sleep(2); }Wednesday, May 25, 2011
  • 89. while (true){ try{ $this->logAction("Checking for messages..."); FIRST COME, //Read Queue $qMessage = $qManager->getMessage(); //If no message, sleep for 3 seconds and try again FIRST SERVED if ($qMessage === null){ $this->logAction("No pending messages..."); sleep(3); continue; } //Retrieve User {... doctrine query for stored twitter handle ...} //Clear Message $this->logAction("Removing message form queue..."); $qManager->deleteMessage($qMessage); //Process User $this->processUser($user); //Warn User $this->sendWarning($user); } catch (Exception $e) { $this->logAction("Exception found:" .$e->getMessage } $this->logAction("Initiating sleep for next loop."); sleep(2); }Wednesday, May 25, 2011
  • 90. while (true){ try{ $this->logAction("Checking for messages..."); FIRST COME, //Read Queue $qMessage = $qManager->getMessage(); //If no message, sleep for 3 seconds and try again FIRST SERVED if ($qMessage === null){ $this->logAction("No getMessage() public function pending messages..."); { sleep(3); $messages = $this->client->getMessages($this->queue->name, 1); continue; } if (count($messages) > 0){ //Retrieve User $qMessage = array_shift($messages); {... doctrine query for stored twitter handle ...} $message = new stdClass(); //Clear Message $message->qMessage = $qMessage; $this->logAction("Removing message form queue..."); $message->decoded = unserialize($qMessage->messagetext); $qManager->deleteMessage($qMessage); return $message; //Process User } $this->processUser($user); return null; //Warn User $this->sendWarning($user); } } catch (Exception $e) { $this->logAction("Exception found:" .$e->getMessage } $this->logAction("Initiating sleep for next loop."); sleep(2); }Wednesday, May 25, 2011
  • 91. while (true){ try{ $this->logAction("Checking for messages..."); FIRST COME, //Read Queue $qMessage = $qManager->getMessage(); //If no message, sleep for 3 seconds and try again FIRST SERVED if ($qMessage === null){ $this->logAction("No getMessage() public function pending messages..."); { sleep(3); $messages = $this->client->getMessages($this->queue->name, 1); continue; } if (count($messages) > 0){ //Retrieve User $qMessage = array_shift($messages); {... doctrine query for stored twitter handle ...} $message = new stdClass(); //Clear Message $message->qMessage = $qMessage; $this->logAction("Removing message form queue..."); $message->decoded = unserialize($qMessage->messagetext); $qManager->deleteMessage($qMessage); return $message; //Process User } $this->processUser($user); return null; //Warn User $this->sendWarning($user); array( } messageid => $messageId, insertiontime => $insertionTime, } catch (Exception $e) { expirationtime => $expirationTime, $this->logAction("Exception found:" .$e->getMessage popreceipt => $popReceipt, timenextvisible => $timeNextVisible, } dequeuecount => $dequeueCount, messagetext => $messageText $this->logAction("Initiating sleep for next loop."); ); sleep(2); }Wednesday, May 25, 2011
  • 92. while (true){ try{ $this->logAction("Checking for messages..."); FIRST COME, //Read Queue $qMessage = $qManager->getMessage(); //If no message, sleep for 3 seconds and try again FIRST SERVED if ($qMessage === null){ $this->logAction("No pending messages..."); sleep(3); continue; } //Retrieve User {... doctrine query for stored twitter handle ...} //Clear Message $this->logAction("Removing message form queue..."); $qManager->deleteMessage($qMessage); //Process User $this->processUser($user); //Warn User $this->sendWarning($user); } catch (Exception $e) { $this->logAction("Exception found:" .$e->getMessage } $this->logAction("Initiating sleep for next loop."); sleep(2); }Wednesday, May 25, 2011
  • 93. while (true){ try{ $this->logAction("Checking for messages..."); FIRST COME, //Read Queue $qMessage = $qManager->getMessage(); //If no message, sleep for 3 seconds and try again FIRST SERVED if ($qMessage === null){ $this->logAction("No pending messages..."); sleep(3); continue; } //Retrieve User {... doctrine query for stored twitter handle ...} //Clear Message $this->logAction("Removing message form queue..."); $qManager->deleteMessage($qMessage); After 20 seconds, message goes //Process User back into Queue $this->processUser($user); //Warn User $this->sendWarning($user); } catch (Exception $e) { $this->logAction("Exception found:" .$e->getMessage } $this->logAction("Initiating sleep for next loop."); sleep(2); }Wednesday, May 25, 2011
  • 94. GOING OUT THE WINDOW • See all changes: github.com/rdohms/Sample-Azure-App • Compare these branches: non-cloud-version x cloud-designed-versionWednesday, May 25, 2011
  • 95. LOOKING BACK BEFORE CLOSING THE WINDOW • Found out what is the Cloud • Looked at reasons on why to choose the Cloud • We took a look at Windows Azure • Peaked at how it affects our code?Wednesday, May 25, 2011
  • 96. FURTHER READING... PHP Development in the Cloud ISBN: 9780981034522 Pages: 172 Authors: Ivo Jansch and Vito Chin http://bit.ly/i9Awk0Wednesday, May 25, 2011
  • 97. GET STARTED, GET HELP • Get a free account: WindowsAzurePass.com • Talk to the Microsoft guys out in the Hall • Ask them about pricing options http://azurephp.com http://phpazure.codeplex.com/ http://azurephptools.codeplex.com/ http://www.ben-waine.co.uk/blog/php-azure http://marvelley.com/category/php/php-on-azure/Wednesday, May 25, 2011
  • 98. twitter.com/rdohmshttp://doh.ms Questions? rafael@doh.ms THANK YOU! Feedback is very important, please visit: joind.in/3417Wednesday, May 25, 2011