2. This talk is…
• sharing some best practices
• sharing some tools with you
• an (incomplete) checklist
• a reminder (hopefully)
Fabrizio Branca
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
• Performance
Fabrizio Branca
4. This talk is about
How to…
• avoid errors
• detect errors
• deal with errors
• notify yourself when errors have occurred
Fabrizio Branca
6. 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
7. Automating
• Automatize error recognition
• Use proper tools
• Automatize error reporting
• Route detailed error reports into your mailbox
Fabrizio Branca
8. 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
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 coding
guidelines and patterns
Fabrizio Branca
11. What does PHP offer?
• log_errors
• display_errors
• error_log
Set values in
• php.ini
• .htaccess / vhost configuration
Fabrizio Branca
12. What does TYPO3 offer?
• devLog, sysLog, Tslog
• devIpMask
• Deprecation log
• Page not found / Page unavailable
• Exception handling
• Error handling
• Debug Console in the BE
Fabrizio Branca
13. Deal with exceptions (I)
How to react when an exception has
occurred?
• Don„t display any details to the user!
• Send a correct HTTP status code (for
search engines and log files)
$GLOBALS['TSFE']->pageNotFoundAndExit($errorHandlerMessage);
$GLOBALS['TSFE']->pageUnavailableAndExit($errorHandlerMessage);
Fabrizio Branca
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 TSLog
Fabrizio Branca
18. 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
19. Bug detection with assertions
• Make sure that variables contain what you
expect at any time (e.g. after calling a function)
• E.g.: Check incoming parameters for correct
type
• 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
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. Bug detection with assertions
See
EXT:pt_tools/res/staticlib/class.tx_pttools_assert.php
or
build your own assert class
Some examples:
• tx_pttools_assert::isValidUid();
• tx_pttools_assert::isNotEmptyString();
Fabrizio Branca
48. 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
49. Monitoring
• Configure your TYPO3 instances to notify
you when errors occur.
• Use Monitoring tools (e.g. Nagios,
Caretaker?)
Fabrizio Branca