Debugging, Monitoring and Profiling in TYPO3


Published on

Sep 09, 2011

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

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Debugging, Monitoring and Profiling in TYPO3

  1. 1. Debugging, Monitoring andProfilingFabrizio Brancafabrizio (dot) branca (at) aoemedia (dot) deTwitter: @fbrnc
  2. 2. This talk is…• sharing some best practices• sharing some tools with you• an (incomplete) checklist• a reminder (hopefully)Fabrizio Branca
  3. 3. 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
  4. 4. This talk is aboutHow to…• avoid errors• detect errors• deal with errors• notify yourself when errors have occurredFabrizio Branca
  5. 5. It„s all about bugsFabrizio Branca
  6. 6. It„s all about bugsEverybody creates bugs. Nobody is perfect.A high percentage of coding time goes into• searching for bugs• fixing bugsIncrease your productivity by reducing this time!Fabrizio Branca
  7. 7. Automating• Automatize error recognition• Use proper tools• Automatize error reporting• Route detailed error reports into your mailboxFabrizio Branca
  8. 8. Bugs• Avoid bugs• through programming style• Spot bugs fast• “Safety nets”: Unit tests, Assertions• Detect them before the customer and/orthe website user finds themFabrizio Branca
  9. 9. Avoid bugs• Use a proper IDE• Syntax checks• Code Completion
  10. 10. 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 patternsFabrizio Branca
  11. 11. What does PHP offer?• log_errors• display_errors• error_logSet values in• php.ini• .htaccess / vhost configurationFabrizio Branca
  12. 12. 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
  13. 13. 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
  14. 14. Page not foundFabrizio Branca
  15. 15. Page unavailableFabrizio Branca
  16. 16. 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 TSLogFabrizio Branca
  17. 17. Exception HandlerFabrizio Branca
  18. 18. Bug detection• Bugs are harder to fix the later they aredetected• Bugs become harder to diagnose thefurther the symptom is removed from thecauseFabrizio Branca
  19. 19. 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• Branca
  20. 20. 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
  21. 21. Bug detection with assertionsSeeEXT:pt_tools/res/staticlib/class.tx_pttools_assert.phporbuild your own assert classSome examples:• tx_pttools_assert::isValidUid();• tx_pttools_assert::isNotEmptyString();Fabrizio Branca
  22. 22. t3lib_div::devLog()Fabrizio Branca
  23. 23. t3lib_div::sysLog()Decides by configuration how to handlesyslog messages• send mail• write to log file• write to OS syslogFabrizio Branca
  24. 24. Custom SysLog HandlerSeeEXT:tcaobjects/res/class.tx_tcaobjects_syslog.phpFabrizio Branca
  25. 25. SysLog notification mailmsg: 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: 1Server:TYPO3_REQUEST_URL: -- none --COOKIE:condensed: 0fe_typo_user: 6b7ccec749891321cb6e7e2fc4c685a4PHPSESSID: 4b8712f5a4c845029da1f2332cf9132bClient:HTTP_USER_AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20100611 Firefox/3.6.4 ( .NET CLR3.5.30729; .NET4.0C)Spider: NoREMOTE_HOST: [null]REMOTE_ADDR: aoeBE_User: -- no user --Trace: [...]
  26. 26. $TYPO3_DB->debug_check_recordset()• Check all database queries• Debug_check_recordset takes care ofwriting log messagesFabrizio Branca
  27. 27. TSlogFabrizio Branca
  28. 28. $TT->push() / ->pull()Use the timetrack object to keep track ofwhat happens in your code.Fabrizio Branca
  29. 29. Reports moduleFabrizio Branca
  30. 30. Reports moduleWrite your own reportsExamples:• Table size• Outdated extensions (extension manager)• TCA Integrity• TCA/database integrity (Like Compare tool)• Extension integrity (dependencies, conflicts)• Free disk space• Server loadFabrizio Branca
  31. 31. Define a strong api• Provide interfaces for hooks.• Allow alternatives (pagerStrategy,viewClass,…)Fabrizio Branca
  32. 32. 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 moduleFabrizio Branca
  33. 33. Keep an eye on the logs…• External tools• Google Webmaster Tools• Wget• Piwik• MySQL• Slow query log• OS (*nix)• SyslogFabrizio Branca
  34. 34. Log ModuleFabrizio Branca
  35. 35. Google Webmaster ToolsFabrizio Branca
  36. 36. Let tools do the analysis• PHP• TSFE• TypoScript• jQuery code• HTML• CSS• RSSFabrizio Branca
  37. 37. Visualizing xdebug profiling
  38. 38. Visualizing xdebug profiling
  39. 39. Visualizing pdepend xml
  40. 40. jQuery Lint„Runtime Reporter“ Branca
  41. 41. 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
  42. 42. Tick
  43. 43. TickFabrizio Branca
  44. 44. Tick
  45. 45. Use validatorsUse validators for validating• HTML• CSS• RSSKeep an eye on editor„s contentFabrizio Branca
  46. 46. 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 publishingFabrizio Branca
  47. 47. Monitoring• Configure your TYPO3 instances to notifyyou when errors occur.• Use Monitoring tools (e.g. Nagios,Caretaker?)Fabrizio Branca
  48. 48. Pingdom
  49. 49. Maintainance• Delete old temp filesfind ../htdocs/typo3temp -type f -mtime +28 -delete• Delete deleted records• Delete unreferenced files• Cleanup/check databaseFabrizio Branca