Beware of cakephp’s requestAction!

We decided to start using database sessions instead of the usual php storage method, just to check if that would fix the extremely annoying problem of cakephp completely ignoring the maximum session time settings (no matter what setting did it have, it always logs out people after 20 minutes).

So seems that it worked, people could be inactive for a while and after that they didn’t find a “You’ve been logged out” message. But it revealed a new problem: each requestAction was forcing the creation of a new Session object. And each time it is made, it generates like 3 or 4 queries. Which absolutely gave me the creeps when I saw the queries list!

I knew about the potential bad performance of requestAction, I had been warned, but I decided to use it for a couple of “blocks” because I couldn’t believe it was going to perform so badly. I could cope with creating a new Dispatcher for handling the request, but those repeated accesses to Session objects are just plain terrible.

I’m impressed no one has noticed it already. It could be solved using a Singleton approach, just as they do with the ConnectionManager. It also could use some kind of cache since all the session functions are in cakephp’s domain when you use the database session handler, so why does it need to query the database to retrieve something that was already retrieved 20 milliseconds again?

I finally removed all the calls to requestAction (by creating an instance of the model which was called by the controller and asking it the values directly, etc) and did a pseudo-cache of the session data in my code, and minimised as much as possible the calls to Session->read. While this is code optimised, it is not readability-optimised. It hurts my eyes to see this structure, it goes against nature and against MVC and against something else I can’t recall now. Endless pain and agony! ARRGHH!

4 Responses to “Beware of cakephp’s requestAction!”

  1. humphr3y says:

    Bueno, no viene muy a cuento, pero como ando mirando… tu página se ve mucho mejor con el IE7 que con el IE6… al menos, ya no tiene el pesado error de que se iba cada vez más a la izquierda en cada comentario…

  2. herotyc says:

    Hi Sole, I’ve done a project with Cakephp, it’s fast-to-develop but lacks good features like a good Ajax handling and documentation.
    I’m willing to try the symphony(http://www.symfony-project.com/) framework, do you know that? maybe you could give me you point of view before I start to use it. Thx

  3. sole says:

    symfony scares me from the moment that has lots of dependencies, we were considering using it and we discarded it because of that. Also it requires php5, which unfortunately most of the hosts still aren’t aware of.

  4. [...] but I couldn’t find a whole lot of information about it. Some of what I did find was pretty negative. The manual suggests that one of the uses of requestAction is to retrieve data from another [...]