Top Banner
Debugging, Monitoring and Profiling Fabrizio Branca fabrizio (dot) branca (at) aoemedia (dot) de Twitter: @fbrnc
51

Debugging, Monitoring and Profiling in TYPO3

Jun 14, 2015

Download

Technology

AOE

Slides of Fabrizio Branca's talk on the TYPO3 Developer Days 2010 (T3DD10)
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Debugging, Monitoring and Profiling in TYPO3

Debugging, Monitoring andProfiling

Fabrizio Brancafabrizio (dot) branca (at) aoemedia (dot) de

Twitter: @fbrnc

Page 2: Debugging, Monitoring and Profiling in TYPO3

This talk is…

• sharing some best practices

• sharing some tools with you

• an (incomplete) checklist

• a reminder (hopefully)

Fabrizio Branca

Page 3: Debugging, Monitoring and Profiling in TYPO3

What is this all about?

• Make your website run smoothly!

• during development…

• and when the site is online

• “Smoothly” is

• No bugs (unexpected behaviour)

• Stability

• PerformanceFabrizio Branca

Page 4: Debugging, Monitoring and Profiling in TYPO3

This talk is about

How to…

• avoid errors

• detect errors

• deal with errors

• notify yourself when errors have occurred

Fabrizio Branca

Page 5: Debugging, Monitoring and Profiling in TYPO3

It„s all about bugs

Fabrizio Branca

Page 6: Debugging, Monitoring and Profiling in TYPO3

It„s all about bugs

Everybody creates bugs. Nobody is perfect.

A high percentage of coding time goes into• searching for bugs

• fixing bugs

Increase your productivity by reducing this time!

Fabrizio Branca

Page 7: Debugging, Monitoring and Profiling in TYPO3

Automating

• Automatize error recognition

• Use proper tools

• Automatize error reporting

• Route detailed error reports into your mailbox

Fabrizio Branca

Page 8: Debugging, Monitoring and Profiling in TYPO3

Bugs

• Avoid bugs

• through programming style

• Spot bugs fast

• “Safety nets”: Unit tests, Assertions

• Detect them before the customer and/or the website user finds them

Fabrizio Branca

Page 9: Debugging, Monitoring and Profiling in TYPO3

Avoid bugs

• Use a proper IDE

• Syntax checks

• Code Completion

Page 10: Debugging, Monitoring and Profiling in TYPO3

Coding style

• Cover all cases: No if without else!

• Use type hints wherever possible

• Stick to patterns

• Increase crearity

• Convention over configuration

• KISS

• Use object collections

• Make it easier for team members to find and fix bugs(increase the truck factor) by sticking to codingguidelines and patterns

Fabrizio Branca

Page 11: Debugging, Monitoring and Profiling in TYPO3

What does PHP offer?

• log_errors

• display_errors

• error_log

Set values in

• php.ini

• .htaccess / vhost configuration

Fabrizio Branca

Page 12: Debugging, Monitoring and Profiling in TYPO3

What does TYPO3 offer?

• devLog, sysLog, Tslog

• devIpMask

• Deprecation log

• Page not found / Page unavailable

• Exception handling

• Error handling

• Debug Console in the BEFabrizio Branca

Page 13: Debugging, Monitoring and Profiling in TYPO3

Deal with exceptions (I)

How to react when an exception hasoccurred?

• Don„t display any details to the user!

• Send a correct HTTP status code (forsearch engines and log files)

$GLOBALS['TSFE']->pageNotFoundAndExit($errorHandlerMessage);

$GLOBALS['TSFE']->pageUnavailableAndExit($errorHandlerMessage);

Fabrizio Branca

Page 14: Debugging, Monitoring and Profiling in TYPO3

Page not found

Fabrizio Branca

Page 15: Debugging, Monitoring and Profiling in TYPO3

Page unavailable

Fabrizio Branca

Page 16: Debugging, Monitoring and Profiling in TYPO3

Deal with exceptions (II)

Handle exceptions within your controllers.

Notify yourself:

• write a message to devLog

• write a message to sysLog

• write a message to TSLog

Fabrizio Branca

Page 17: Debugging, Monitoring and Profiling in TYPO3

Exception Handler

Fabrizio Branca

Page 18: Debugging, Monitoring and Profiling in TYPO3

Bug detection

• Bugs are harder to fix the later they are detected

• Bugs become harder to diagnose the further the symptom is removed from the cause

Fabrizio Branca

Page 19: Debugging, Monitoring and Profiling in TYPO3

Bug detection with assertions

• Make sure that variables contain what youexpect at any time (e.g. after calling a function)

• E.g.: Check incoming parameters for correcttype

• Simple one line call:tx_pttools_assert::isValidUid($this->params['uid']);

• Throws an exception if assertion is not true• http://articles.sitepoint.com/article/bug-detection-php-assertions

http://debuggable.com/posts/assert-the-yummyness-of-your-cake:480f4dd6-7fe0-4113-9776-458acbdd56cb

Fabrizio Branca

Page 20: Debugging, Monitoring and Profiling in TYPO3

Bug detection with assertions

• Assertions are easy to use.

• Don„t assume anything, check it!• Example: ini_set()

• No substitute for unit tests!

Fabrizio Branca

Page 21: Debugging, Monitoring and Profiling in TYPO3

Bug detection with assertions

See EXT:pt_tools/res/staticlib/class.tx_pttools_assert.php

orbuild your own assert class

Some examples:• tx_pttools_assert::isValidUid();

• tx_pttools_assert::isNotEmptyString();

Fabrizio Branca

Page 22: Debugging, Monitoring and Profiling in TYPO3
Page 23: Debugging, Monitoring and Profiling in TYPO3

t3lib_div::devLog()

Fabrizio Branca

Page 24: Debugging, Monitoring and Profiling in TYPO3

t3lib_div::sysLog()

Decides by configuration how to handle syslog messages

• send mail

• write to log file

• write to OS syslog

Fabrizio Branca

Page 25: Debugging, Monitoring and Profiling in TYPO3

Custom SysLog Handler

See EXT:tcaobjects/res/class.tx_tcaobjects_syslog.php

Fabrizio Branca

Page 26: Debugging, Monitoring and Profiling in TYPO3

SysLog notification mail

msg: Assertion "isValidUid" failed!extKey: pt_toolsseverity: 3exceptionClass: tx_pttools_exceptionAssertiondebugMsg:

file: /var/www/burghalle/integration/htdocs/typo3conf/ext/aoe_burg/controller/class.tx_aoeburg_controller_extranet.phpline: 78function: tx_aoeburg_controller_extranet::initassertType: isValidUidval: expected: 1

Server: TYPO3_REQUEST_URL: http://www.integration.burghalle.aoe-works.de/xtranet/uebersicht/artikel-

bearbeiten/e/typo3conf/ext/burghalle_template/i/white-75.pngHTTP_REFERER: http://www.integration.burghalle.aoe-works.de/xtranet/uebersicht/artikel-bearbeiten/e/saveContent.htmlPOST: -- none --COOKIE:

condensed: 0fe_typo_user: 6b7ccec749891321cb6e7e2fc4c685a4PHPSESSID: 4b8712f5a4c845029da1f2332cf9132b

Client: HTTP_USER_AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4 ( .NET CLR

3.5.30729; .NET4.0C)Spider: NoREMOTE_HOST: [null]REMOTE_ADDR: 217.19.187.106

User: FE_User: aoeBE_User: -- no user --

Trace: [...]

Page 27: Debugging, Monitoring and Profiling in TYPO3

$TYPO3_DB->debug_check_recordset()

• Check all database queries

• Debug_check_recordset takes care ofwriting log messages

Fabrizio Branca

Page 28: Debugging, Monitoring and Profiling in TYPO3

TSlog

Fabrizio Branca

Page 29: Debugging, Monitoring and Profiling in TYPO3

$TT->push() / ->pull()

Use the timetrack object to keep track of what happens in your code.

Fabrizio Branca

Page 30: Debugging, Monitoring and Profiling in TYPO3

Reports module

Fabrizio Branca

Page 31: Debugging, Monitoring and Profiling in TYPO3

Reports module

Write your own reports

Examples:• Table size

• Outdated extensions (extension manager)

• TCA Integrity

• TCA/database integrity (Like Compare tool)

• Extension integrity (dependencies, conflicts)

• Free disk space

• Server load

Fabrizio Branca

Page 32: Debugging, Monitoring and Profiling in TYPO3

Define a strong api

• Provide interfaces for hooks.

• Allow alternatives (pagerStrategy, viewClass,…)

Fabrizio Branca

Page 33: Debugging, Monitoring and Profiling in TYPO3

Keep an eye on the logs…

• Webserver

• Apache error log

• PHP error log

• TYPO3

• Log module (Core error handler…)

• Admin Panel

• RealUrl

• error log

• are all paramters encoded?

• Deprecation log

• Reports module

Fabrizio Branca

Page 34: Debugging, Monitoring and Profiling in TYPO3

Keep an eye on the logs…

• External tools

• Google Webmaster Tools

• Wget

• Piwik

• MySQL

• Slow query log

• OS (*nix)

• Syslog

Fabrizio Branca

Page 35: Debugging, Monitoring and Profiling in TYPO3

Log Module

Fabrizio Branca

Page 36: Debugging, Monitoring and Profiling in TYPO3
Page 37: Debugging, Monitoring and Profiling in TYPO3

Google Webmaster Tools

Fabrizio Branca

Page 38: Debugging, Monitoring and Profiling in TYPO3

Let tools do the analysis

• PHP

• TSFE

• TypoScript

• jQuery code

• HTML

• CSS

• RSSFabrizio Branca

Page 39: Debugging, Monitoring and Profiling in TYPO3

Visualizing xdebug profiling

Page 40: Debugging, Monitoring and Profiling in TYPO3

Visualizing xdebug profiling

Page 41: Debugging, Monitoring and Profiling in TYPO3

Visualizing pdepend xml

Page 42: Debugging, Monitoring and Profiling in TYPO3

jQuery Lint

„Runtime Reporter“

http://james.padolsey.com/javascript/jquery-lint/

Fabrizio Branca

Page 43: Debugging, Monitoring and Profiling in TYPO3

TypoScript Check (lint)

Proof of concept!

Xclassing tslib_content:

function stdWrap($content,$conf) {

$this->getLinkChecker()->check($conf, 'stdWrap');

return parent::stdWrap($content, $conf);

}

Fabrizio Branca

Page 44: Debugging, Monitoring and Profiling in TYPO3

Tick

Page 45: Debugging, Monitoring and Profiling in TYPO3

Tick

Fabrizio Branca

Page 46: Debugging, Monitoring and Profiling in TYPO3

Tick

Page 47: Debugging, Monitoring and Profiling in TYPO3

Use validators

Use validators for validating

• HTML

• CSS

• RSS

Keep an eye on editor„s content

Fabrizio Branca

Page 48: Debugging, Monitoring and Profiling in TYPO3

Spot performance killers

• Use USER_INTs only if really needed.

• Create links with cHashes

• Avoid putting USER_INTs on all pages(load them via ajax)

• Cache headers

• Static publishing

Fabrizio Branca

Page 49: Debugging, Monitoring and Profiling in TYPO3

Monitoring

• Configure your TYPO3 instances to notify you when errors occur.

• Use Monitoring tools (e.g. Nagios, Caretaker?)

Fabrizio Branca

Page 50: Debugging, Monitoring and Profiling in TYPO3

Pingdom

Page 51: Debugging, Monitoring and Profiling in TYPO3

Maintainance

• Delete old temp filesfind ../htdocs/typo3temp -type f -mtime +28 -delete

• Delete deleted records

• Delete unreferenced files

• Cleanup/check database

Fabrizio Branca