O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Depurando aplicações PHP like a BOSS

903 visualizações

Publicada em

Gravação (vídeo) da palestra: https://www.infoq.com/br/presentations/depurando-aplicacoes-php-like-a-boss

Palestra apresentada nos seguintes eventos:

- DrupalCamp Campinas, em 25/06/2016;
- The Developers Conference (TDC) São Paulo, em 09/07/2016;
- PHP Conference Brazil, em 09/12/2016;
- PHPSP + Locaweb #3, em 18/02/2017.

Publicada em: Software
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://shorturl.at/mzUV6 } ......................................................................................................................... Download Full EPUB Ebook here { http://shorturl.at/mzUV6 } ......................................................................................................................... Download Full doc Ebook here { http://shorturl.at/mzUV6 } ......................................................................................................................... Download PDF EBOOK here { http://shorturl.at/mzUV6 } ......................................................................................................................... Download EPUB Ebook here { http://shorturl.at/mzUV6 } ......................................................................................................................... Download doc Ebook here { http://shorturl.at/mzUV6 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui

Depurando aplicações PHP like a BOSS

  1. 1. Depurando aplicações PHP like a BOSS Thiago Rodrigues Eng. de Software Sr. CI&T - PHPSP
  2. 2. Thiago Rodrigues Bacharel em Sistemas de Informação pela Universidade do Estado de Minas Gerais (UEMG); Engenheiro de Software Sênior na CI&T Programador PHP há 11 anos; Evangelista PHPSP e co-organizador do PHPSP Campinas Entusiasta do software livre Gammer
  3. 3. Depuração - O que é? Definição formal: Depuração (em inglês: debugging, debug) é o processo de encontrar e reduzir defeitos num aplicativo de software ou mesmo em hardware. [..] https://pt.wikipedia.org/wiki/Depuração ● diariamente despendemos esforço considerável ● é um processo analítico ● é um processo repetitivo ● é incremental (dividir para conquistar) ● pode haver muita pressão envolvida
  4. 4. Depuração - Habilidade necessária O bom desenvolvedor é capaz de depurar e resolver problemas com: ● tranquilidade ● efetividade ● produtividade ● clareza ● assertividade
  5. 5. Depuração - domínio de ferramentas Para executar bem qualquer trabalho é fundamental dominar ferramentas que auxiliam na execução do mesmo. A habilidade de criar e usar ferramentas foi e ainda é fundamental para espécie humana.
  6. 6. Quais ferramentas vocês usam para depurar aplicações PHP?
  7. 7. Ferramentas de depuração - Não existe bala de prata Diferentes problemas demandam ferramentas diferentes. É fundamental conhecer diversas ferramentas, entender quando usar e como usar.
  8. 8. Bê-a-bá da depuração de aplicações PHP <?php echo 'Hello world!';
  9. 9. Bê-a-bá da depuração de aplicações PHP <?php $vetor = array( 'frutas' => array( 'banana', 'maça', 'laranja' ), 'vegetais' => array( 'alface', 'rúcula', 'couve' ), ); echo $vetor;
  10. 10. Bê-a-bá da depuração de aplicações PHP <?php $vetor = array( 'frutas' => array( 'banana', 'maça', 'laranja' ), 'vegetais' => array( 'alface', 'rúcula', 'couve' ), ); print_r($vetor);
  11. 11. Bê-a-bá da depuração de aplicações PHP <?php $vetor = array( 'frutas' => array( 'banana', 'maça', 'laranja' ), 'vegetais' => array( 'alface', 'rúcula', 'couve' ), ); echo '<pre>'; print_r($vetor);
  12. 12. Bê-a-bá da depuração de aplicações PHP <?php $vetor = array( '', NULL, 'laranja', 123, '123', 1.0, '1.0', ); echo '<pre>'; print_r($vetor);
  13. 13. Bê-a-bá da depuração de aplicações PHP <?php $vetor = array( '', NULL, 'laranja', 123, '123', 1.0, '1.0', ); echo '<pre>'; var_dump($vetor);
  14. 14. Bê-a-bá da depuração de aplicações PHP <?php $vetor = array( // elementos ); ob_start(); echo '<pre>'; var_dump($vetor); $info = ob_get_clean(); file_put_contents('/tmp/debug.html', $info); echo 'Oi ;)';
  15. 15. Problemas comuns da abordagem "imprimir na tela" ● Esforço repetitivo ● Não exibe todo o contexto de variáveis ● Dificulta o entendimento de estruturas de dados complexas ● Requer a quebra de funcionalidade para testes em produção ○ Você pode se dar a esse luxo? O que os usuários vão pensar? ● Desperdiça-se muito tempo tentando identificar fluxos complexos imprimindo valores seguido da função exit() ou die(). ● De vez em quando algum desses echo/print_r/var_dump são esquecidos, acarretando na quebra de funcionalidades ou do layout. ● Identificação de problemas de performance é extremamente onerosa
  16. 16. Ensino fundamental da depuração de aplicações PHP Ajustar php.ini para exibir qualquer tipo de erro: error_reporting = E_ALL display_errors = On # Desligar em PROD. Verificar logs do servidor web enquanto as requisições estão ocorrendo (stream): sudo tail -f /var/log/apache2/error.log [outro/file]
  17. 17. Tipos de depuração Debugging Conecta-se ao software e controla o fluxo de execução da aplicação e obtém seu estado. Tracing Imprime informações em momentos chaves, tais como a pilha de execução da aplicação. Profiling Coleta e mensura diversos dados estatísticos da aplicação, tais como tempo de execução, memória utilizada, quantidades de chamadas, etc.
  18. 18. Xdebug A mais poderosa ferramenta de depuração PHP. Principais funcionalidades: ● Debugging ● Tracing ● Profiling ● Proteção contra loop infinito ● Deixa o var_dump bonito
  19. 19. Xdebug - Instalação No Linux: sudo apt-get install php5-xdebug No Mac (usando brew): sudo brew install php56-xdebug
  20. 20. Xdebug - Tracing
  21. 21. Xdebug - "embeleza" o var_dump
  22. 22. Xdebug - Configurando depuração remota No servidor web - xdebug.ini: xdebug.remote_connect_back=1 xdebug.remote_enable=1 Túnel SSH (necessário somente para aplicações remotas) ssh -R 9000:localhost:9000 thiago@site.com
  23. 23. Xdebug - Configurando depuração remota no PHPStorm 1) Abra a janela Preferences e navegue até PHP > Servers. 2) Preencha o Name, Host e Porta do servidor PHP. 3) Se for um servidor remoto, habilite "Use path mappings" e mapeie a raiz do projeto local com o caminho absoluto do projeto no servidor remoto. 4) Clique em OK para salvar e fechar a janela.
  24. 24. Xdebug - Configurando depuração remota no PHPStorm 1) Vá até o menu Run e clique em Edit Configurations. 2) Clique no botão + e depois em PHP Web Application. 3) Preencha o campo Name; no campo Server selecione o servidor criado no slide anterior e coloque / em Start URL. 4) Clique em OK para salvar e fechar a janela.
  25. 25. Xdebug - Iniciando a depuração no PHPStorm Se a depuração for remota, criar o túnel SSH antes. 1) Vá até o menu Run e clique em Debug 'nome'. 2) Será aberto uma janela do navegador.
  26. 26. Xdebug - Tela de depuração no PHPStorm
  27. 27. Xdebug - Depuração no PHPStorm clique na imagem p/abrir o vídeo no YouTube
  28. 28. Xdebug - Configurando profiling xdebug.ini xdebug.profiler_enable_trigger=1 xdebug.profiler_enable=1 xdebug.profiler_output_dir="/var/www/phpsp" Visite o site, note que ele criará alguns arquivos cachegrind.out na pasta especificada. No PHPStorm: Acesse Tools > Analyze Xdebug Profiler Snapshot e selecione algum arquivo cachegrind.out.
  29. 29. Xdebug - Analisando profiling no PHPStorm clique na imagem p/abrir o vídeo no YouTube
  30. 30. Xdebug - Analisando profiling no KCachegrind
  31. 31. XHProf Ferramenta para profiling.
  32. 32. XHProf - Gráfico de chamadas
  33. 33. Drupal 8 - Webprofiler
  34. 34. Blackfire - outra ferramenta de profiling
  35. 35. Conclusão ● Precisa checar uma estrutura de dados básica? var_dump ● Precisa investigar o fluxo de execução? Xdebug ● Precisa investigar uma estrutura de dados complexa? Xdebug ● Precisa melhorar a performance de uma página? Utilize uma ferramenta de profiling antes de sair atirando para todo lado. Invista seu tempo em ferramentas de depuração para ganhar produtividade.
  36. 36. Contato xthiago@gmail.com xthiago.com + PHP dia 20/agosto em Campinas: phpspima.com.br

×