php jedi - boas práticas e alta performance
DESCRIPTION
Palestra apresentada no II Encontro PHP-PBTRANSCRIPT
![Page 2: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/2.jpg)
"PHP is not about purity in CS principles or architecture; it is about solving the ugly web
problem with an admittedly ugly, but extremely functional and convenient solution. If you are
looking for purity, you are in the wrong boat. Get out now before you get hit by a wet cat!" -
Rasmus Lerdorf
![Page 3: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/3.jpg)
Beleza nem sempre é fundamental
![Page 4: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/4.jpg)
Mas um códigobem escrito faz
toda a diferença!
![Page 5: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/5.jpg)
Boas práticas
![Page 6: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/6.jpg)
Evite o spaghetti
![Page 7: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/7.jpg)
Divida em camadas
![Page 8: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/8.jpg)
• Para separar a aparência da lógica de negócio
• Smarty
• Savant, TinyButStrong, PHPTAL, XSLT, ...
![Page 9: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/9.jpg)
Siga um padrão de
codificação
![Page 10: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/10.jpg)
• Por exemplo, as convenções do Java:
• CamelCase
• Classes começam com maiúscula: FrontController, DatabaseConnection, RestClient
• Variáveis (atributos), funções (métodos) começam com minúscula: $user, $this->name, print(), $this->getName()
![Page 11: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/11.jpg)
• Constantes, toda em maiúscula com underline para separar palavras: DATABASE_LOGIN, BASE_DIR
![Page 12: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/12.jpg)
• Existem diversas convenções para PHP
• PEAR Coding Standardshttp://pear.php.net/manual/en/standards.php
• Zend Framework Coding Standard for PHPhttp://framework.zend.com/manual/en/coding-standard.html
![Page 13: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/13.jpg)
Use o PEAR
![Page 14: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/14.jpg)
Use o PEAR
PHPExtension and Application Repository
![Page 15: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/15.jpg)
• Pacotes escritos por membros ativos da comunidade PHP
• Tudo testado por um time exigente de controle de qualidade.
• Gerenciamento “a la apt-get”:Ex.: pear install Logpear upgrade PHPUnitpear uninstall Text_CAPTCHA
![Page 16: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/16.jpg)
Não reinvente a roda
![Page 17: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/17.jpg)
• Crie do zero apenas o que é específico da sua aplicação
• Reuso de código facilita a manutenção
• Códigos de fontes confiáveis como PEAR e Zend Framework são bem testados antes de serem disponibilizados.
![Page 18: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/18.jpg)
Diga não aoCtrl + C, Ctrl + V
![Page 19: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/19.jpg)
• Se o mesmo código precisa ser usado em mais de um lugar, não copie!
• Encapsule numa função/método
![Page 20: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/20.jpg)
Frameworks
![Page 21: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/21.jpg)
• Zend Framework
• CakePHP
• Symfony
• Prado
• CodeIgniter
![Page 22: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/22.jpg)
• Ajuda a separar camadas
• Padrões de codificação
• Reaproveitamento de código
•Aprecie com moderação!*
![Page 23: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/23.jpg)
Escolha bons nomes
![Page 24: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/24.jpg)
• Nomes relevantes ajudam no entendimento do código
• Variáveis com nomes como: $xpto, $foo, $bar, etc... não dizem nada sobre o que é guardado lá (assim como funções, classes e métodos)
![Page 25: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/25.jpg)
Comente o código
![Page 26: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/26.jpg)
Mas comentários não disfarçam códigosmal escritos
Comente o código
![Page 27: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/27.jpg)
"Don't comment bad code - rewrite it."
Brian W. Kernighan and P. J. Plaugher
![Page 28: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/28.jpg)
Keep It Simple, Stupid!
![Page 29: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/29.jpg)
Evite qualquer complexidade desnecessária
Keep It Simple, Stupid!
![Page 30: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/30.jpg)
Utilize padrões para se comunicar
![Page 31: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/31.jpg)
Em alguns lugares do oriente médio, esse gesto...
![Page 32: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/32.jpg)
Então é melhor não inventar!
seria interpretado assim...
![Page 33: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/33.jpg)
XML
![Page 34: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/34.jpg)
XML
![Page 35: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/35.jpg)
JSON
![Page 36: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/36.jpg)
JSON
![Page 37: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/37.jpg)
Quebre grandes blocos de código em blocos menores
![Page 38: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/38.jpg)
Quebre grandes blocos de código em blocos menores
Classes e métodos muito grandes devem
ser refatorados
![Page 39: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/39.jpg)
Não use Windows
![Page 40: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/40.jpg)
“PHP Windows developers are second-class citizens” – Rasmus Lerdorf
![Page 41: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/41.jpg)
• Windows não é a plataforma ideal para desenvolvedores
• Não tem um terminal poderoso
• Não vem “de fábrica” com compiladores úteis para nós, como o gcc
• Não reproduz o ambiente de produção mais comum em PHP, o LAMP
![Page 42: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/42.jpg)
• Não tem um gerenciador de pacotes que permita atualizar e adicionar/remover módulos do PHP de maneira trivial.
• Não tem um bom gerenciamento de memória.
• Dê uma chance ao Linux ou algum sabor de Unix (FreeBSD, Mac OS X, etc...)
![Page 43: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/43.jpg)
Tratamento de erros
![Page 44: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/44.jpg)
Tratamento de erros
Desenvolva no modo E_STRICT
![Page 45: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/45.jpg)
Tratamento de erros
Desenvolva no modo E_STRICT
Use Exceptions
e trate-as
![Page 46: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/46.jpg)
display_errors = off
Afinal o usuário não vai depurar o seu
código
![Page 47: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/47.jpg)
Não use o operador @ para suprimir
erros. Atrapalha o debug e deixa a
execução mais lenta
![Page 48: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/48.jpg)
Não confie no usuário
![Page 49: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/49.jpg)
Não confie no usuário
filtre toda entrada
![Page 50: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/50.jpg)
e escape toda saída
![Page 51: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/51.jpg)
![Page 52: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/52.jpg)
Use o Twitter para
algo útil
![Page 53: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/53.jpg)
Crie um perfil privado para a sua aplicação
![Page 54: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/54.jpg)
Crie um perfil privado para a sua aplicação
onde os únicos followers são os desenvolvedores
![Page 55: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/55.jpg)
Utilizando a API, faça com que sua aplicação dê uma “twittada” a cada erro
![Page 56: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/56.jpg)
Performance e Escalabilidade
![Page 57: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/57.jpg)
Performance
![Page 58: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/58.jpg)
Performance
a habilidade que uma aplicação tem de atingir um objetivo, como por exemplo responder no menor tempo possível
![Page 59: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/59.jpg)
Escalabilidade
![Page 60: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/60.jpg)
Escalabilidade
a habilidade de uma aplicação manter a performance quando a carga de trabalho aumenta.
![Page 61: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/61.jpg)
PHP não é tão rápido...
![Page 62: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/62.jpg)
Porém sua arquitetura
share-nothing simplifica a
escalabilidade
![Page 63: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/63.jpg)
E PHP dificilmente é o gargalo
![Page 64: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/64.jpg)
A maior parte do tempo é gasto no
banco de dados ou com o carregamento
do front-end
![Page 65: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/65.jpg)
Sempre dá para espremer e melhorar
![Page 66: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/66.jpg)
Xdebug arrebenta no profiling!
![Page 67: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/67.jpg)
• Instale a extensão Xdebug
• Habilite a opção xdebug.profiler_enable caso queira que toda execução gere o log
• Ou a opção xdebug.profiler_enable_trigger para que o log só seja gerado quando você passar?XDEBUG_PROFILE na URL
![Page 68: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/68.jpg)
• Rode o script que você quer analisar
• Abra o log gerado pelo Xdebug no KCacheGrind caso use Linux, ou no WebGrind em qualquer outra plataforma.
![Page 70: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/70.jpg)
http://code.google.com/p/webgrind/
![Page 71: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/71.jpg)
• xdebug_memory_usage( ) diz quanto de memória o script está usando no momento da chamada
• xdebug_peak_memory_usage( ) diz qual o valor máximo de memória que foi usada durante a execução
![Page 72: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/72.jpg)
Testes de carga
![Page 74: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/74.jpg)
Macintosh:~ felipe$ ab -c 10 -t 30 -b -k 'http://shoprizer.localhost/'This is ApacheBench, Version 2.3 <$Revision: 655654 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking shoprizer.localhost (be patient)Finished 4379 requests
Server Software: Apache/2.0.59Server Hostname: shoprizer.localhostServer Port: 80
Document Path: /Document Length: 22320 bytes
Concurrency Level: 10Time taken for tests: 30.010 secondsComplete requests: 4379Failed requests: 0Write errors: 0Total transferred: 99436344 bytesHTML transferred: 97806240 bytesRequests per second: 145.92 [#/sec] (mean)Time per request: 68.532 [ms] (mean)Time per request: 6.853 [ms] (mean, across all concurrent requests)Transfer rate: 3235.74 [Kbytes/sec] received
![Page 75: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/75.jpg)
Macintosh:~ felipe$ siege -b -t30s 'http://shoprizer.localhost/'** SIEGE 2.67** Preparing 10 concurrent users for battle.The server is now under siege...Lifting the server siege... done.Transactions: 4909 hitsAvailability: 100.00 %Elapsed time: 29.84 secsData transferred: 104.49 MBResponse time: 0.06 secsTransaction rate: 164.51 trans/secThroughput: 3.50 MB/secConcurrency: 9.93Successful transactions: 4909Failed transactions: 0Longest transaction: 2.28Shortest transaction: 0.00
![Page 76: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/76.jpg)
Caching
![Page 77: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/77.jpg)
APCFaz cache do opcode do
PHP. Evitando que seja recompilado a cada
execução
![Page 78: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/78.jpg)
APCFaz cache do opcode do
PHP. Evitando que seja recompilado a cada
execução
Também permite fazer cache de informações em memória
![Page 79: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/79.jpg)
APC<?php
$valor = 'Informação que quero armazenar';
//Armazena o valor no cache em memória do APCapc_store('id_da_informacao', $valor);
// O valor pode ser recuperado em diferentes scripts através do apc_fetchvar_dump(apc_fetch('id_da_informacao'));
?>
![Page 80: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/80.jpg)
Memcached
![Page 81: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/81.jpg)
Memcached
É necessária a execução de um daemon
![Page 82: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/82.jpg)
Memcached
É necessária a execução de um daemon
Ideal para objetos pequenos
![Page 83: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/83.jpg)
Memcached<?php$memcache = new Memcache();//Conecta no servidor memcached$memcache->connect('localhost', 11211);
$valor = 'Informação que quero armazenar';
//Envia via socket a informação para o memcached$memcache->set('id_da_informacao', $valor);
//Recupera a informaçãovar_dump($memcache->get('id_da_informacao'));?>
![Page 84: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/84.jpg)
Smarty
Além de separar lógica e visualização, faz
caching
![Page 85: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/85.jpg)
Smarty<?phprequire 'smarty/Smarty.class.php';
$id = (int) $_GET['id'];$smarty = new Smarty();$smarty->caching = 1;
if(!$smarty->is_cached('noticia.tpl',$id)) { //Carrega do banco de dados}$smarty->display('noticia.tpl',$id);?>
![Page 86: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/86.jpg)
Frameworks(de novo? Já vi esse slide!)
![Page 87: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/87.jpg)
• Frameworks ajudam em aplicações com funcionalidades comuns.
• As camadas genéricas de um framework acabam gerando overhead.
• Na necessidade de alta performance, você vai precisar abrir mão de certos “luxos” para ter mais flexibilidade e fazer o tunning.
![Page 88: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/88.jpg)
Armazenamento em MySQL
![Page 89: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/89.jpg)
Performance é com MyISAM
Armazenamento em MySQL
Integridade é com InnoDB
![Page 90: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/90.jpg)
Front-end
![Page 91: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/91.jpg)
Front-end
Firebug + YSlow!
![Page 92: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/92.jpg)
![Page 93: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/93.jpg)
<?php $card = array( 'nome' => 'Felipe Ribeiro', 'site' => 'http://feliperibeiro.com', 'e-mail' => '[email protected]', 'fone' => '(83) 9979-3161' ); var_dump($card); ?>
![Page 94: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/94.jpg)
• YSlow:http://developer.yahoo.com/yslow
• Siege:http://www.joedog.org/JoeDog/Siege
• Xdebug Profiling: http://xdebug.org/docs/profiler
• Filter: http://php.net/filter
![Page 95: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/95.jpg)
• Simple is HardRasmus Lerdorf - http://talks.php.net/show/lca09
• Building Scalable Web SitesCal Henderson - O’Reilly Media, Inc. 2006
• Desenvolvendo aplicações Web escaláveisElton Minetto - http://www.eltonminetto.net/docs/app_web_escalaveis.pdf
• Scalable PHPCal Henderson - http://www.slideshare.net/iamcal/scalable-php-presentation
![Page 96: PHP Jedi - Boas Práticas e Alta Performance](https://reader038.vdocument.in/reader038/viewer/2022102700/54bd62644a7959f3178b462b/html5/thumbnails/96.jpg)
http://www.flickr.com/photos/jeniee/123356305http://flickr.com/photos/chriskueh/2277679121http://www.flickr.com/photos/awfulsara/59884516/http://www.flickr.com/photos/zach_manchester/2302683790/http://flickr.com/photos/toofarnorth/2691097127http://flickr.com/photos/suttonhoo22/247107220http://flickr.com/photos/conskeptical/191048988http://flickr.com/photos/kazk/198640938http://flickr.com/photos/jakecaptive/49915119http://www.myfreewallpapers.net/music/wallpapers/kiss-fire.jpghttp://flickr.com/photos/chrisjones/12827874/http://flickr.com/photos/jorel314/2950338887http://flickr.com/photos/jmarty/1804061993http://flickr.com/photos/cw_ye/2952033606http://flickr.com/photos/vgm8383/2191223539http://flickr.com/photos/petecarr/475437514http://flickr.com/photos/capsicina/361735510http://flickr.com/photos/schlomo/3304431482/http://flickr.com/photos/seandreilinger/133250112/http://flickr.com/photos/mesolimbo/2543327787http://flickr.com/photos/hamed/155343130/http://flickr.com/photos/deniscollette/1817034358http://flickr.com/photos/robertjosiah/2690194447/http://flickr.com/photos/blahflowers/1571042854/http://flickr.com/photos/dey/2203203306/http://flickr.com/photos/thomashawk/24089964http://flickr.com/photos/jasohill/118616905/http://flickr.com/photos/tunnelarmr/2435107204http://flickr.com/photos/oberazzi/318947873http://flickr.com/photos/polegario/230055697/http://flickr.com/photos/cwm/300412682/