Post on 10-May-2015
description
Open a Window, see the clouds
Rafael Dohmsphoto credit: Denis Grzetic
Wednesday, May 25, 2011
Rafael Dohms
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.
phot
o cr
edit:
Eli W
hite
Wednesday, May 25, 2011
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
WHAT IS THE CLOUD?not just another buzzword bingo word
Wednesday, May 25, 2011
REGULAR HOSTING
• Shared account, VPS or Local Machine
•One machine, one place
• Pay by month
Wednesday, May 25, 2011
REGULAR HOSTING
• Shared account, VPS or Local Machine
•One machine, one place
• Pay by month
Self
Wednesday, May 25, 2011
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, SaaS
Wednesday, May 25, 2011
Hardware/Network
Operating System
Software
Application
Data
Wednesday, May 25, 2011
Hardware/Network
Operating System
Software
Application
Data
UpgradingConfiguring
ApacheMySQL
Cooling Cabling
DevelopingDeploying
Storing Sharing
Wednesday, May 25, 2011
IaaS“Infrastructure as a Service”
Hardware/Network
Operating System
Software
Application
Data
Wednesday, May 25, 2011
IaaS“Infrastructure as a Service”
Hardware/Network
Operating System
Software
Application
Data
you
them
Wednesday, May 25, 2011
PaaS“Platform as a Service”
Hardware/Network
Operating System
Software
Application
Data
Wednesday, May 25, 2011
PaaS“Platform as a Service”
Hardware/Network
Operating System
Software
Application
Data
you
them
Wednesday, May 25, 2011
SaaS“Software as a Service”
Hardware/Network
Operating System
Software
Application
Data
Wednesday, May 25, 2011
SaaS“Software as a Service”
Hardware/Network
Operating System
Software
Application
Datayou
them
Wednesday, May 25, 2011
WHY CHOOSE THE CLOUD?What are the advantages of using the cloud?
X
Wednesday, May 25, 2011
time
traffic
THE UTILITY MODEL
Wednesday, May 25, 2011
time
traffic
THE UTILITY MODEL
Wednesday, May 25, 2011
time
traffic
peak
THE UTILITY MODEL
Wednesday, May 25, 2011
time
traffic
peak
THE UTILITY MODEL
Wednesday, May 25, 2011
time
traffic
peak
THE UTILITY MODEL
Wednesday, May 25, 2011
IaaS Paas SaaS
costs
server managment.
software management
product deploy
Wednesday, May 25, 2011
AVAILABILITY
Wednesday, May 25, 2011
AVAILABILITY
Wednesday, May 25, 2011
AVAILABILITY
Wednesday, May 25, 2011
SCALABILITYStateless Compute + Durable Storage
Wednesday, May 25, 2011
SCALABILITYStateless Compute + Durable Storage
Wednesday, May 25, 2011
LET’S LOOK INSIDE
Wednesday, May 25, 2011
Fabric
StorageCompute
Windows Azure Overview
Wednesday, May 25, 2011
AppFabric
Fabric
developer
Middleware, used for developing, deploying and managing your applications
Wednesday, May 25, 2011
Fabric
StorageCompute
Wednesday, May 25, 2011
Compute
Web Role Worker Role VM Role
Web application running on top of
IIS
Background processing
Windows Server 2008 instance that can be loaded on
demand
Wednesday, May 25, 2011
Fabric
StorageCompute
Wednesday, May 25, 2011
Storage
Table Storage Blob Storage QueueSQL Azure
Compatible with SQL ServerStructured Storage Text and binary
dataMessaging between Web and Worker
CDN
Data Storage
Cached version of any resource in
storage with a URI
Wednesday, May 25, 2011
UP & RUNNING
• Requisites:
• IIS7 Tools
• Azure SDK (install DevAppFabric, the azure emulator)
• Command Line Tools
• Command line tools for PHP
for Development and Deployment
Wednesday, May 25, 2011
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 IDE
Wednesday, May 25, 2011
Developer Environm
entW
indow A
zure
CodeAzure Emulator (Dev fabric)
Packaging tools (command line or eclipse)
Azure(AppFabric)
SQLAzure Storage
Package + Service Configuration
Wednesday, May 25, 2011
Developer Environm
entW
indow A
zure
CodeAzure Emulator (Dev fabric)
Packaging tools (command line or eclipse)
Azure(AppFabric)
SQLAzure Storage
Package + Service Configuration
PHP
Wednesday, May 25, 2011
Developer Environm
entW
indow A
zure
CodeAzure Emulator (Dev fabric)
Packaging tools (command line or eclipse)
Azure(AppFabric)
SQLAzure Storage
Package + Service Configuration
PHP
Wednesday, May 25, 2011
Developer Environm
entW
indow A
zure
CodeAzure Emulator (Dev fabric)
Packaging tools (command line or eclipse)
Azure(AppFabric)
SQLAzure Storage
Package + Service Configuration
PHP php package.php --project="twitter-azure" --target="c:\azure-build" --source="C:\twitter-azure" --defaultDoc="public/index.php" --phpRuntime="C:\Program Files (x86)\PHP\v5.3" --cleanRebuild --runDevFabric
Wednesday, May 25, 2011
Developer Environm
entW
indow A
zure
CodeAzure Emulator (Dev fabric)
Packaging tools (command line or eclipse)
Azure(AppFabric)
SQLAzure Storage
Package + Service Configuration
PHP
Wednesday, May 25, 2011
THE GOOD
•REST APIs
• Storage
•Diagnostics
•Relational DB: SQL Azure
•Role Architecture
Wednesday, May 25, 2011
THE BAD
•Windows-only Management
•No Azure Emulator for non-Windows OS
•No Packaging Command Line tools for non-Windows OS
Wednesday, May 25, 2011
HOW DOES THAT AFFECT CODE?What tools can we use and how should we design our apps
Wednesday, May 25, 2011
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
Scaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
No Local StorageScaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
No Local Storage Session sharingScaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
No Local Storage
Worker Roles
Session sharingScaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
No Local Storage
Worker Roles
Session sharing
Queues
Scaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
Storage
No Local Storage
Worker Roles
Session sharing
Queues
Scaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
Storage
No Local Storage
Worker Roles
Session sharing
Queues
What kind?
Scaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
Storage
No Local Storage
Worker Roles
Session sharing
Queues
What kind?Table / Blob
Scaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
Storage
No Local Storage
Worker Roles
Session sharing
Queues
What kind?Table / Blob Framework or PHP SDK
Scaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
Storage
No Local Storage
Worker Roles
Session sharing
Queues
What kind?RelationalDatabase
Table / Blob Framework or PHP SDK
Scaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
Code PHP on IIS/Windows
Architecture
Storage
No Local Storage
Worker Roles
Session sharing
Queues
What kind?RelationalDatabase
Table / Blob
Migrate to SQL Azure
Framework or PHP SDK
Scaling
WHAT DO I WORRY ABOUT?
Wednesday, May 25, 2011
AZURE-READY FRAMEWORKS
Wednesday, May 25, 2011
WHAT MAKES IT COMPATIBLE?
Does it run on PHP on Windows?
Does it have API Handlers?
Does it offer MS SQL Compatibility?
Code
Tools
Database
Wednesday, May 25, 2011
• Blobs, Tables and Queues (CRUD operations)
• Helper Classes for HTTP transport, AuthN/AuthZ, REST and Error Management
• Manageability, Instrumentation and Logging support
• Not tested, but should work well.
Tools
Database
Wednesday, May 25, 2011
•MS-SQL Drivers* are compatible with SQLAzure
Powered by Doctrine:
Database
* Using pdo_sql_server, possibly pdo_dblib
Wednesday, May 25, 2011
• 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
AZURE PHP SDK
• Services:
•Blob Storage
•Table Storage
•Queue Storage
•Diagnostic Tools
• Compatible with PHP 5+
Wednesday, May 25, 2011
GOING OUT THE WINDOW
• 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 Queue
Sample migration to the cloud
Wednesday, May 25, 2011
GOING OUT THE WINDOW
• 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 Queue
Sample migration to the cloud
Wednesday, May 25, 2011
Twitter OAuth
Wait for it...
Wednesday, May 25, 2011
Twitter OAuth
Wait for it...
Wednesday, May 25, 2011
Twitter OAuth
Wait for it...
Wednesday, May 25, 2011
Twitter OAuth
Wait for it...
MySQL
Wednesday, May 25, 2011
Twitter OAuth
Wait for it...
Results
MySQL
Wednesday, May 25, 2011
Twitter OAuth
Wait for it...
Results
MySQL
Wednesday, May 25, 2011
Twitter OAuth
Wait for it...
Results
MySQL
Wednesday, May 25, 2011
Twitter OAuth
Don’t call me, i’ll call you
Wednesday, May 25, 2011
Twitter OAuth
Don’t call me, i’ll call you
Queue
Wednesday, May 25, 2011
Twitter OAuth
Don’t call me, i’ll call you
Worker
Queue
Wednesday, May 25, 2011
Twitter OAuth
Don’t call me, i’ll call you
Worker
Queue
Wednesday, May 25, 2011
Twitter OAuth
Don’t call me, i’ll call you
Worker
Queue
Wednesday, May 25, 2011
Twitter OAuth
Don’t call me, i’ll call you
Worker
SQLAzure
Queue
Wednesday, May 25, 2011
Twitter OAuth
Don’t call me, i’ll call you
Worker
SQLAzure
Queue
Wednesday, May 25, 2011
Twitter OAuth
Don’t call me, i’ll call you
Results
Worker
SQLAzure
Queue
Wednesday, May 25, 2011
Twitter OAuth
Don’t call me, i’ll call you
Results
Worker
SQLAzure
Queue
WorkerWorkerWorkerWorkerWorkerWorkerWorkerWorkerWorkerWorker
Wednesday, May 25, 2011
USING SQLAZURE
doctrine.dbal.connection_options: driver: pdo_sqlsrv dbname: twitter-sample-app host: pl69qjwy8k.database.windows.net port: 1433 user: rdohmsDemo@pl69qjwy8k password: *password*
PDO MSSQL Driver
Wednesday, May 25, 2011
LINE THEM UP IN THE QUEUE //Add user to our Queue $qItem = new \stdClass(); $qItem->twitter_handle = $twitterInfo->screen_name; $qManager = new Azure\Queue($this->getApp()->getConfig('azure')); $qManager->addToQueue($qItem);
Wednesday, May 25, 2011
LINE THEM UP IN THE QUEUE //Add user to our Queue $qItem = new \stdClass(); $qItem->twitter_handle = $twitterInfo->screen_name; $qManager = new Azure\Queue($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
LINE THEM UP IN THE QUEUE //Add user to our Queue $qItem = new \stdClass(); $qItem->twitter_handle = $twitterInfo->screen_name; $qManager = new Azure\Queue($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);
public function addToQueue($item) { $this->client->putMessage($this->queue->name, serialize($item)); }
__contruct()
Wednesday, May 25, 2011
FIRST COME, FIRST SERVED
while (true){ try{ $this->logAction("Checking for messages..."); //Read Queue $qMessage = $qManager->getMessage();
//If no message, sleep for 3 seconds and try again 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
FIRST COME, FIRST SERVED
while (true){ try{ $this->logAction("Checking for messages..."); //Read Queue $qMessage = $qManager->getMessage();
//If no message, sleep for 3 seconds and try again 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
FIRST COME, FIRST SERVED
while (true){ try{ $this->logAction("Checking for messages..."); //Read Queue $qMessage = $qManager->getMessage();
//If no message, sleep for 3 seconds and try again 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); }
public function getMessage() { $messages = $this->client->getMessages($this->queue->name, 1); if (count($messages) > 0){ $qMessage = array_shift($messages); $message = new \stdClass(); $message->qMessage = $qMessage; $message->decoded = unserialize($qMessage->messagetext); return $message; } return null; }
Wednesday, May 25, 2011
FIRST COME, FIRST SERVED
while (true){ try{ $this->logAction("Checking for messages..."); //Read Queue $qMessage = $qManager->getMessage();
//If no message, sleep for 3 seconds and try again 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); }
public function getMessage() { $messages = $this->client->getMessages($this->queue->name, 1); if (count($messages) > 0){ $qMessage = array_shift($messages); $message = new \stdClass(); $message->qMessage = $qMessage; $message->decoded = unserialize($qMessage->messagetext); return $message; } return null; }
array( 'messageid' => $messageId, 'insertiontime' => $insertionTime, 'expirationtime' => $expirationTime, 'popreceipt' => $popReceipt, 'timenextvisible' => $timeNextVisible, 'dequeuecount' => $dequeueCount, 'messagetext' => $messageText );
Wednesday, May 25, 2011
FIRST COME, FIRST SERVED
while (true){ try{ $this->logAction("Checking for messages..."); //Read Queue $qMessage = $qManager->getMessage();
//If no message, sleep for 3 seconds and try again 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
FIRST COME, FIRST SERVED
while (true){ try{ $this->logAction("Checking for messages..."); //Read Queue $qMessage = $qManager->getMessage();
//If no message, sleep for 3 seconds and try again 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); }
After 20 seconds, message goes back into Queue
Wednesday, May 25, 2011
GOING OUT THE WINDOW
• See all changes: github.com/rdohms/Sample-Azure-App
• Compare these branches:
non-cloud-version x cloud-designed-version
Wednesday, May 25, 2011
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
FURTHER READING...
PHP Development in the Cloud
ISBN: 9780981034522Pages: 172Authors: Ivo Jansch and Vito Chin
http://bit.ly/i9Awk0
Wednesday, May 25, 2011
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.comhttp://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
THANK YOU!rafael@doh.ms
Feedback is very important, please visit: joind.in/3417
twitter.com/rdohmshttp://doh.ms
Questions?
Wednesday, May 25, 2011