[Solar-talk] Problem with APC + objects created inside views / view helpers

Paul M Jones pmjones at ciaweb.net
Mon May 28 14:16:05 PDT 2007


Hi Rodrigo,

> I use APC, and yesterday I've noticed a strange thing using it. When a
> model object is created inside a view helper and it is is not cached
> yet (Solar_Sql_Model_Catalog data), PDO throws an exception:
>
> array ( 'exception' => PDOException::__set_state(array( 'message' =>
> 'You cannot serialize or unserialize PDO instances', [...]
>
> This happens with objects created using factory, or dependencies
> created in the view part. Inside a helper, for example:
>
>     $res = Solar::registry('model_poll')->fetchAll();
>
> If 'model_poll' is a dependency for a never called and thus not cached
> model data, the exception is thrown. If it is a registered object
> (registered in the controller), no problem happens. APC doesn't deal
> very well with models created in the view part of the app.
>
> (I use some helpers as "page modules", created independently of the
> controller, and so models and views are called there)

I don't know what to tell you on this one.  I don't know why it would  
happen in a View, but not in a Controller.  (I was going to say  
something along the lines of "don't instantiate Models in a View" but  
it looks like you're doing the equivalent of a component here, so I  
guess that's OK.  ;-)


> A workaround was to register the model objects in the controller, and
> not their dependencies. So in the view it is already built and well
> cached.

This sounds like a decent workaround to me; in general, I think the  
Controller should deliver everything the View needs anyway, but  
that's just me.


> I like APC, and I think the latest versions work pretty well with
> Solar, and all previous problems with class loading etc have been
> solved. But I would like to hear recommendations, if you use other
> cache systems.

We've been using Lighttpd and Xcache with great success.





--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.  <http://solarphp.com>

Join the Solar community wiki!  <http://solarphp.org>

Savant: The simple, elegant, and powerful solution for
templates in PHP.  <http://phpsavant.com>




More information about the solar-talk mailing list