Useful tips for symfony2/doctrine optimization

In the LinkedIn-symfony-group I stumbled upon a very useful link:

http://labs.octivi.com/mastering-symfony2-performance-doctrine/

This is a must-read for all doctrine-beginners, I wish i woud have read it when I started… Here are the points in short:

  • use the Symfony Profiler toolbar
  • avoid object hydration
  • use IDs for referencing rather than whole object
  • use update-statement
  • use lazy collections
  • never load entities in a loop

More infos can be found in the article.

Table inheritance with Doctrine

Currently I am programming a web-application with Symfony. In this app we got different kind of users: patients, doctors, experts, admins and so on. All of these users share some attributes (username, password, email), but some attributes only apply to several usertypes. A doctor for example has a departement, an expert a phone-number etc.

In the object oriented world of PHP this is an easy task: Patient extends User. But thanks to the magic of Doctrine this can be used within MySQL as well!

Daniel Barsotti wrote an excellent post about it: http://blog.liip.ch/archive/2012/03/27/table-inheritance-with-doctrine.html

Works like a charm!