debugging, monitoring and profiling in typo3

Post on 14-Jun-2015

6.038 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

Slides of Fabrizio Branca's talk on the TYPO3 Developer Days 2010 (T3DD10)

TRANSCRIPT

Debugging, Monitoring andProfiling

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

Twitter: @fbrnc

This talk is…

• sharing some best practices

• sharing some tools with you

• an (incomplete) checklist

• a reminder (hopefully)

Fabrizio Branca

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

This talk is about

How to…

• avoid errors

• detect errors

• deal with errors

• notify yourself when errors have occurred

Fabrizio Branca

It„s all about bugs

Fabrizio Branca

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

Automating

• Automatize error recognition

• Use proper tools

• Automatize error reporting

• Route detailed error reports into your mailbox

Fabrizio Branca

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

Avoid bugs

• Use a proper IDE

• Syntax checks

• Code Completion

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

What does PHP offer?

• log_errors

• display_errors

• error_log

Set values in

• php.ini

• .htaccess / vhost configuration

Fabrizio Branca

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

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 not found

Fabrizio Branca

Page unavailable

Fabrizio Branca

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

Exception Handler

Fabrizio Branca

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

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

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

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

t3lib_div::devLog()

Fabrizio Branca

t3lib_div::sysLog()

Decides by configuration how to handle syslog messages

• send mail

• write to log file

• write to OS syslog

Fabrizio Branca

Custom SysLog Handler

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

Fabrizio Branca

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: [...]

$TYPO3_DB->debug_check_recordset()

• Check all database queries

• Debug_check_recordset takes care ofwriting log messages

Fabrizio Branca

TSlog

Fabrizio Branca

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

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

Fabrizio Branca

Reports module

Fabrizio Branca

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

Define a strong api

• Provide interfaces for hooks.

• Allow alternatives (pagerStrategy, viewClass,…)

Fabrizio Branca

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

Keep an eye on the logs…

• External tools

• Google Webmaster Tools

• Wget

• Piwik

• MySQL

• Slow query log

• OS (*nix)

• Syslog

Fabrizio Branca

Log Module

Fabrizio Branca

Google Webmaster Tools

Fabrizio Branca

Let tools do the analysis

• PHP

• TSFE

• TypoScript

• jQuery code

• HTML

• CSS

• RSSFabrizio Branca

Visualizing xdebug profiling

Visualizing xdebug profiling

Visualizing pdepend xml

jQuery Lint

„Runtime Reporter“

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

Fabrizio Branca

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

Tick

Tick

Fabrizio Branca

Tick

Use validators

Use validators for validating

• HTML

• CSS

• RSS

Keep an eye on editor„s content

Fabrizio Branca

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

Monitoring

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

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

Fabrizio Branca

Pingdom

Maintainance

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

• Delete deleted records

• Delete unreferenced files

• Cleanup/check database

Fabrizio Branca

top related