98
Open a Window, see the clouds Rafael Dohms photo credit: Denis Grzetic Saturday, July 9, 2011

TDC 2011 - Open a Window, see the clouds

Embed Size (px)

DESCRIPTION

Sua aplicação esta pronta para decolar na nuvem? O que significa isso? Com o que você precisa se preocupar? Quais frameworks e ferramentas são necessários e quais novos conceitos você deve colocar na sua caixa de ferramentas PHP para estar pronto? Conheça um pouco mais sobre a plataforma Windows Azure e suas funcionalidades, além de descobrir mais quais ferramentas e frameworks estão prontos para se beneficiarem deste novo paradigma.

Citation preview

Page 1: TDC 2011 - Open a Window, see the clouds

Open a Window, see the clouds

Rafael Dohmsphoto credit: Denis Grzetic

Saturday, July 9, 2011

Page 2: TDC 2011 - Open a Window, see the clouds

Rafael Dohms

Evangelista PHP, membro ativo da Comunidade PHP e certificado ZCE. Ele ajudou na fundação de dois Grupos de Usuários de PHP ao longo do tempo e hoje compartilha a coordenação do PHPSP. Desenvolvedor, gamer e apaixonado por código ele também é host do primeiro podcast de PHP do Brasil: PHPSPCast.

Atualmente ele trabalha na equipe SWAT do grupo MIH, uma equipe de experts que fornecem conhecimento técnico para o grupo além de trabalhar com P&D buscando novos nichos da internet e tecnologia. Seu papel como Desenvolvedor Sênior é codar, treinar e auxiliar outras empresas e se divertir enquanto faz isso.

phot

o cr

edit:

Eli W

hite

Saturday, July 9, 2011

Page 3: TDC 2011 - Open a Window, see the clouds

OLHANDO PELA JANELA

• O que é a nuvem?

• Por que escolher a nuvem?

• Vamos conhecer o Windows Azure

• Como isso vai afetar meu código?

Saturday, July 9, 2011

Page 4: TDC 2011 - Open a Window, see the clouds

O QUE É A NUVEM?não é só mais uma palavra no buzzword bingo

Saturday, July 9, 2011

Page 5: TDC 2011 - Open a Window, see the clouds

HOSPEDAGEM COMUM

• Conta compatilhada, VPS ou máquina local

• Uma máquina, um local

• Pagamento mensal

Saturday, July 9, 2011

Page 6: TDC 2011 - Open a Window, see the clouds

HOSPEDAGEM COMUM

• Conta compatilhada, VPS ou máquina local

• Uma máquina, um local

• Pagamento mensal

Própria

Saturday, July 9, 2011

Page 7: TDC 2011 - Open a Window, see the clouds

COMPUTAÇÃO NA NUVEM

• Menos “apego físico” (virtualização)

• Uma ou mais máquinas ou “instancias”

• Geograficamente espalhada

• Pagamento por hora/recurso

• “abstração” de recursos

• 3 Sabores: IaaS, PaaS, SaaS

Saturday, July 9, 2011

Page 8: TDC 2011 - Open a Window, see the clouds

Hardware/Rede

Sistema Operacional

Software

Aplicação

Dados

Saturday, July 9, 2011

Page 9: TDC 2011 - Open a Window, see the clouds

Hardware/Rede

Sistema Operacional

Software

Aplicação

Dados

UpgradesConfiguração

ApacheMySQL

Resfriamento Cabeamento

DesenvolvimentoPublicação

Armazenamento Compartilhar

Saturday, July 9, 2011

Page 10: TDC 2011 - Open a Window, see the clouds

IaaS“Infrastructure as a Service”

Hardware/Rede

Sistema Operacional

Software

Aplicação

Dados

“Infraestrutura como Serviço”

Saturday, July 9, 2011

Page 11: TDC 2011 - Open a Window, see the clouds

IaaS“Infrastructure as a Service”

Hardware/Rede

Sistema Operacional

Software

Aplicação

Dados

você

eles

“Infraestrutura como Serviço”

Saturday, July 9, 2011

Page 12: TDC 2011 - Open a Window, see the clouds

PaaS“Platform as a Service”

Hardware/Rede

Sistema Operacional

Software

Aplicação

Dados

“Plataforma como Serviço”

Saturday, July 9, 2011

Page 13: TDC 2011 - Open a Window, see the clouds

PaaS“Platform as a Service”

Hardware/Rede

Sistema Operacional

Software

Aplicação

Dados

você

eles

“Plataforma como Serviço”

Saturday, July 9, 2011

Page 14: TDC 2011 - Open a Window, see the clouds

SaaS“Software as a Service”

Hardware/Rede

Sistema Operacional

Software

Aplicação

Dados

“Software como Serviço”

Saturday, July 9, 2011

Page 15: TDC 2011 - Open a Window, see the clouds

SaaS“Software as a Service”

Hardware/Rede

Sistema Operacional

Software

Aplicação

Dadosvocê

eles

“Software como Serviço”

Saturday, July 9, 2011

Page 16: TDC 2011 - Open a Window, see the clouds

POR QUE ESCOLHER A NUVEM?Quais são as vantagens de escolher a nuvem?

X

Saturday, July 9, 2011

Page 17: TDC 2011 - Open a Window, see the clouds

tempo

trafego

O MODELO CONTA DE LUZ

Saturday, July 9, 2011

Page 18: TDC 2011 - Open a Window, see the clouds

tempo

trafego

O MODELO CONTA DE LUZ

Saturday, July 9, 2011

Page 19: TDC 2011 - Open a Window, see the clouds

tempo

trafego

pico

O MODELO CONTA DE LUZ

Saturday, July 9, 2011

Page 20: TDC 2011 - Open a Window, see the clouds

tempo

trafego

pico

O MODELO CONTA DE LUZ

Saturday, July 9, 2011

Page 21: TDC 2011 - Open a Window, see the clouds

tempo

trafego

pico

O MODELO CONTA DE LUZ

Saturday, July 9, 2011

Page 22: TDC 2011 - Open a Window, see the clouds

IaaS Paas SaaS

custos

gerenciamento do servidor

gerenciamento do software

publicação da aplicação

Saturday, July 9, 2011

Page 23: TDC 2011 - Open a Window, see the clouds

DISPONIBILIDADE

Saturday, July 9, 2011

Page 24: TDC 2011 - Open a Window, see the clouds

DISPONIBILIDADE

Saturday, July 9, 2011

Page 25: TDC 2011 - Open a Window, see the clouds

DISPONIBILIDADE

Saturday, July 9, 2011

Page 26: TDC 2011 - Open a Window, see the clouds

ESCALABILIDADEComputação sem estado + Armazenamento durável

Saturday, July 9, 2011

Page 27: TDC 2011 - Open a Window, see the clouds

ESCALABILIDADEComputação sem estado + Armazenamento durável

Saturday, July 9, 2011

Page 28: TDC 2011 - Open a Window, see the clouds

OLHANDO POR DENTRO

Saturday, July 9, 2011

Page 29: TDC 2011 - Open a Window, see the clouds

Fabric

StorageCompute

Windows Azure

Saturday, July 9, 2011

Page 30: TDC 2011 - Open a Window, see the clouds

AppFabric

Fabric

developer

Middleware, usado para desenvolver, testar, publicar e gerenciar sua aplicação.

Saturday, July 9, 2011

Page 31: TDC 2011 - Open a Window, see the clouds

Fabric

StorageCompute

Saturday, July 9, 2011

Page 32: TDC 2011 - Open a Window, see the clouds

Compute

Web Role Worker Role VM Role

Aplicação Web rodando sobre o

IIS

Processamento em plano de fundo

Máquina virtual de Windows Server 2008 carregada sob demanda

Saturday, July 9, 2011

Page 33: TDC 2011 - Open a Window, see the clouds

Fabric

StorageCompute

Saturday, July 9, 2011

Page 34: TDC 2011 - Open a Window, see the clouds

Storage

Table Storage Blob Storage QueueSQL Azure

Compatível com o SQL Server

Armazenamento estruturado

Texto e dados binários

Troca de mensagens entre o Web e o Worker

CDN

Armazenamento de dados

Versão cacheada de qualquer recurso

com uma URI

Saturday, July 9, 2011

Page 35: TDC 2011 - Open a Window, see the clouds

PRONTO PRA RODAR

• Requisitos:

• IIS7 e ferramentas

• Azure SDK (instala o DevAppFabric, o simulador de azure)

• Command Line Tools (linha de comando)

• Command line tools for PHP

para Desenvolver e Publicar

Saturday, July 9, 2011

Page 36: TDC 2011 - Open a Window, see the clouds

CAIXA DE FERRAMENTAS

• Command Line tools for PHP

• Cria o pacote da aplicação e roda no emulador, simulando o computacional e o armazenamento.

• Azure Tools para Eclipse

• Torna a maioria dos processos “next, next finish” e fornece uma IDE completa.

Saturday, July 9, 2011

Page 37: TDC 2011 - Open a Window, see the clouds

Am

biente do Desenvolvedor

Window

Azure

CódigoSimulador Azure (Dev fabric)

Ferramentas de empacotamento(linha de comando ou eclipse)

Azure(AppFabric)

SQLAzure Storage

Pacote + Configuração do Serviço

Saturday, July 9, 2011

Page 38: TDC 2011 - Open a Window, see the clouds

Am

biente do Desenvolvedor

Window

Azure

CódigoSimulador Azure (Dev fabric)

Ferramentas de empacotamento(linha de comando ou eclipse)

Azure(AppFabric)

SQLAzure Storage

Pacote + Configuração do Serviço

PHP

Saturday, July 9, 2011

Page 39: TDC 2011 - Open a Window, see the clouds

Am

biente do Desenvolvedor

Window

Azure

CódigoSimulador Azure (Dev fabric)

Ferramentas de empacotamento(linha de comando ou eclipse)

Azure(AppFabric)

SQLAzure Storage

Pacote + Configuração do Serviço

PHP

Saturday, July 9, 2011

Page 40: TDC 2011 - Open a Window, see the clouds

Am

biente do Desenvolvedor

Window

Azure

CódigoSimulador Azure (Dev fabric)

Ferramentas de empacotamento(linha de comando ou eclipse)

Azure(AppFabric)

SQLAzure Storage

Pacote + Configuração do Serviço

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

Saturday, July 9, 2011

Page 41: TDC 2011 - Open a Window, see the clouds

Am

biente do Desenvolvedor

Window

Azure

CódigoSimulador Azure (Dev fabric)

Ferramentas de empacotamento(linha de comando ou eclipse)

Azure(AppFabric)

SQLAzure Storage

Pacote + Configuração do Serviço

PHP

Saturday, July 9, 2011

Page 42: TDC 2011 - Open a Window, see the clouds

O BOM

• APIs em REST

• Armazenamento

• Diagnósticos

• BD Relacional: SQL Azure

• Arquitetura por “Roles”

Saturday, July 9, 2011

Page 43: TDC 2011 - Open a Window, see the clouds

O RUIM

• Gerenciamento apenas pelo Windows

• Sem Emulador Azure para SO não-Windows

• Sem ferramentas de empacotamento para SO não-Windows

Saturday, July 9, 2011

Page 44: TDC 2011 - Open a Window, see the clouds

COMO ISSO AFETA MEU CÓDIGO?Que ferramentas podemos usar e como devemos desenhar

nossas aplicações?

Saturday, July 9, 2011

Page 45: TDC 2011 - Open a Window, see the clouds

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 46: TDC 2011 - Open a Window, see the clouds

Código

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 47: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 48: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 49: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 50: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Sem ArmazenamentoLocal

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 51: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Sem ArmazenamentoLocal

Compartilhamento de sessão

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 52: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Sem ArmazenamentoLocal

Worker Roles

Compartilhamento de sessão

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 53: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Sem ArmazenamentoLocal

Worker Roles

Compartilhamento de sessão

Filas

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 54: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Armazenamento

Sem ArmazenamentoLocal

Worker Roles

Compartilhamento de sessão

Filas

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 55: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Armazenamento

Sem ArmazenamentoLocal

Worker Roles

Compartilhamento de sessão

Filas

Que tipo?

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 56: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Armazenamento

Sem ArmazenamentoLocal

Worker Roles

Compartilhamento de sessão

Filas

Que tipo?Tabela / Blob

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 57: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Armazenamento

Sem ArmazenamentoLocal

Worker Roles

Compartilhamento de sessão

Filas

Que tipo?Tabela / Blob Framework ou PHP SDK

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 58: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Armazenamento

Sem ArmazenamentoLocal

Worker Roles

Compartilhamento de sessão

Filas

Que tipo?Banco de Dados

Relacional

Tabela / Blob Framework ou PHP SDK

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 59: TDC 2011 - Open a Window, see the clouds

Código PHP rodando no IIS/Windows

Arquitetura

Armazenamento

Sem ArmazenamentoLocal

Worker Roles

Compartilhamento de sessão

Filas

Que tipo?Banco de Dados

Relacional

Tabela / Blob

Migrar para SQL Azure

Framework ou PHP SDK

Escalando a aplicação

COM O QUE DEVO ME PREOCUPAR?

Saturday, July 9, 2011

Page 60: TDC 2011 - Open a Window, see the clouds

FRAMEWORKS PRONTOS PARA O AZURE

Saturday, July 9, 2011

Page 61: TDC 2011 - Open a Window, see the clouds

O QUE FAZ ELE SER COMPATÍVEL?

Roda usando PHP no Windows?

Tem wrappers das APIs?

É compatível com MS SQL Server?

Código

Ferramentas

Banco de Dados

Saturday, July 9, 2011

Page 62: TDC 2011 - Open a Window, see the clouds

• Blobs, Tables e Queues (operações CRUD)

• Classes auxiliares para transporte HTTP, AuthN/AuthZ, REST and Gerenciamento de Erros

• Gerenciamento, Instrumentação e supporte a logs

• Não testado, mas deve funcionar.

Ferramentas

Banco de Dados

Saturday, July 9, 2011

Page 63: TDC 2011 - Open a Window, see the clouds

• Drivers de MS-SQL* são compatíveis com SQLAzure

Powered by Doctrine:

Banco de Dados

* Usando pdo_sql_server, possivelmente o pdo_dblib

Saturday, July 9, 2011

Page 64: TDC 2011 - Open a Window, see the clouds

• PHP roda normalmente no Azure, qualquer framework vai funcionar.

• Outras ferramentas para se comunicar com recursos como: BD, Filas etc...

• Estes aqui já foram testados!

Saturday, July 9, 2011

Page 65: TDC 2011 - Open a Window, see the clouds

AZURE PHP SDK

• Serviços:

• Blob Storage

• Table Storage

• Queue Storage

• Diagnostic Tools

• Compatível com PHP 5+

Saturday, July 9, 2011

Page 66: TDC 2011 - Open a Window, see the clouds

SAINDO PELA JANELA

• Aplicação de teste: “Twitter RT Calculator”

• Objetivo: Analisar sues últimos tweets, verificar quais foram re-tuitados e fazer cálculos baseado em palavras e localizações.

• Exemplificar a migração:

• Banco de dados: MySQL > SQLAzure

• Mover o processamento para um Worker Role e usar a Fila

Aplicação de teste para ilustrar

Saturday, July 9, 2011

Page 67: TDC 2011 - Open a Window, see the clouds

SAINDO PELA JANELA

• Aplicação de teste: “Twitter RT Calculator”

• Objetivo: Analisar sues últimos tweets, verificar quais foram re-tuitados e fazer cálculos baseado em palavras e localizações.

• Exemplificar a migração:

• Banco de dados: MySQL > SQLAzure

• Mover o processamento para um Worker Role e usar a Fila

Aplicação de teste para ilustrar

Saturday, July 9, 2011

Page 68: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Segura ai..

Saturday, July 9, 2011

Page 69: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Segura ai..

Saturday, July 9, 2011

Page 70: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Segura ai..

Saturday, July 9, 2011

Page 71: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Segura ai..

MySQL

Saturday, July 9, 2011

Page 72: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Segura ai..

Resultados

MySQL

Saturday, July 9, 2011

Page 73: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Segura ai..

Resultados

MySQL

Saturday, July 9, 2011

Page 74: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Segura ai..

Resultados

MySQL

Saturday, July 9, 2011

Page 75: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Te ligo mais tarde..

Saturday, July 9, 2011

Page 76: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Te ligo mais tarde..

Queue

Saturday, July 9, 2011

Page 77: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Te ligo mais tarde..

Worker

Queue

Saturday, July 9, 2011

Page 78: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Te ligo mais tarde..

Worker

Queue

Saturday, July 9, 2011

Page 79: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Te ligo mais tarde..

Worker

Queue

Saturday, July 9, 2011

Page 80: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Te ligo mais tarde..

Worker

SQLAzure

Queue

Saturday, July 9, 2011

Page 81: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Te ligo mais tarde..

Worker

SQLAzure

Queue

Saturday, July 9, 2011

Page 82: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Te ligo mais tarde..

Resultados

Worker

SQLAzure

Queue

Saturday, July 9, 2011

Page 83: TDC 2011 - Open a Window, see the clouds

Twitter OAuth

Te ligo mais tarde..

Resultados

Worker

SQLAzure

Queue

WorkerWorkerWorkerWorkerWorkerWorkerWorkerWorkerWorkerWorker

Saturday, July 9, 2011

Page 84: TDC 2011 - Open a Window, see the clouds

USANDO 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

Saturday, July 9, 2011

Page 85: TDC 2011 - Open a Window, see the clouds

TODOS PARA A FILA //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);

Saturday, July 9, 2011

Page 86: TDC 2011 - Open a Window, see the clouds

TODOS PARA A FILA //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()

Saturday, July 9, 2011

Page 87: TDC 2011 - Open a Window, see the clouds

TODOS PARA A FILA //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()

Saturday, July 9, 2011

Page 88: TDC 2011 - Open a Window, see the clouds

PRIMEIRO QUE ENTRA, PRIMEIRO

QUE SAI

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); }

Saturday, July 9, 2011

Page 89: TDC 2011 - Open a Window, see the clouds

PRIMEIRO QUE ENTRA, PRIMEIRO

QUE SAI

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); }

Saturday, July 9, 2011

Page 90: TDC 2011 - Open a Window, see the clouds

PRIMEIRO QUE ENTRA, PRIMEIRO

QUE SAI

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; }

Saturday, July 9, 2011

Page 91: TDC 2011 - Open a Window, see the clouds

PRIMEIRO QUE ENTRA, PRIMEIRO

QUE SAI

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 );

Saturday, July 9, 2011

Page 92: TDC 2011 - Open a Window, see the clouds

PRIMEIRO QUE ENTRA, PRIMEIRO

QUE SAI

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); }

Saturday, July 9, 2011

Page 93: TDC 2011 - Open a Window, see the clouds

PRIMEIRO QUE ENTRA, PRIMEIRO

QUE SAI

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); }

Após 20 segundos, a mensagem volta para a fila

Saturday, July 9, 2011

Page 94: TDC 2011 - Open a Window, see the clouds

SAINDO PELA JANELA

• Veja todas mudanças: github.com/rdohms/Sample-Azure-App

• Compare estes branches:

non-cloud-version x cloud-designed-version

Saturday, July 9, 2011

Page 95: TDC 2011 - Open a Window, see the clouds

FECHANDO A JANELA

• Descobrimos o que é a nuvem

• Vimos razões por que escolher a nuvem

• Conhecemos o Windows Azure e seus recursos

• Olhamos rapidamente em como isso afeta nosso código

Saturday, July 9, 2011

Page 96: TDC 2011 - Open a Window, see the clouds

LEITURA COMPLEMENTAR...

PHP Development in the Cloud

ISBN: 9780981034522Pages: 172Authors: Ivo Jansch and Vito Chin

http://bit.ly/i9Awk0

Saturday, July 9, 2011

Page 97: TDC 2011 - Open a Window, see the clouds

COMECE A BRINCAR..

• Conta de teste gratuita: WindowsAzurePass.com

• Procure o pessoal da Microsoft no evento

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/

Saturday, July 9, 2011

Page 98: TDC 2011 - Open a Window, see the clouds

[email protected]

twitter.com/rdohmshttp://doh.ms

Perguntas?

Avalie essa palestra: http://joind.in/3572

http://slides.doh.ms

Saturday, July 9, 2011