
It has been 3 months since I, as a hobby, started writing a project on a new Symfony 2. Further in the article I will try to share with the habrasocommunity the problems that a developer may face. The article is aimed at people already familiar with the architecture of Symfony and Doctrine.
Problem 1. Doctrine 2. Result Cache. Serializing Entities.
Doctrine 2 allows us to cache requests, but does not recommend doing this with Entity.
If you’re still an entity, you’ll be able to keep track of your organization.
In any case, if we decide to cache the request, then for each Entity it is necessary to implement a Serializable interface. In this case, objects that came from the cache can not be correctly processed by the manager. He considers them new and tries to re-insert into the database. For everything to work correctly, you must either reload the object or not use caching in this case.
Example.
')
Problem 2. Symfony2. HTTP Cache and Security Component.
The framework caching ideology is based on
the HTTP specification , which allows the use of proxy caches. For example,
Varnish . Plus a big, because The page is given to the client without loading the framework itself.

But this cache becomes useless if the site will use the built-in user authorization. In this case, Symfony2 creates a session for each user, considering it anonymous. And if there is a session, then there is a unique cookie. As a result, the cache works for each site visitor separately, because considers it authorized.
I have not yet found a solution to this problem. Perhaps the community will help.Also, based on the ideology of caching, Symfony2 is better not to use in projects where the content changes depending on the authorization of the user. For example, voting for a topic in Habré, where the following states exist: you can vote, I voted positively, negatively, voting is over, etc. Or, for example, a form for adding a comment to a publication, where there is a possibility of commenting by anonymous users.
Load test
By happy coincidence, I have two projects similar in functionality. One is written in symfony 1.4, and the other is written in symfony2.
And oddly enough, a simple load test of the main pages showed that the project on Symfony 1.4 is faster:
- Symfony 1.4 approximately 2550 requests in 30 seconds at a competition 10.
- Symfony2 approximately 1750 requests in 30 seconds at a competition 10.
Projects are hosted on a dedicated server with a four-core processor (Intel Core2 Quad CPU Q9550) and 8G RAM.
Sites on which the tests were conducted:
- http://dreamiech.ru - Symfony 1.4
- http://dvjournal.ru - Symfony 2