Nogyara wrote:
> 
> The type of caching APC does (opcode caching) works AUTOMATICALLY, so you
> don't have to care about it at all. 
> 

Yes and no.  Rasmus Lerdorf has explained (http://pooteeweet.org/blog/538)
that opcode caching is a compile-time optimization.  Runtime inclusion of
code happens after compile-time is past, and therefore cannot use the opcode
cache.

Basically if you use "require_once" in the global part of a PHP script, it's
resolved at compile-time and APC can fetch the code from its opcode cache
for the file you require (and any other files required by that file).

However, any runtime "require_once" is resolved too late to benefit from the
opcode cache.  For example, loading classes in a function, loading classes
depending on a PHP variable, and use of autoload.  The code has to be
fetched from the filesystem at runtime and compiled on the fly.  It's as if
you aren't using an opcode cache solution.

Some OO architectures necessarily load code at runtime.  For example, in a
ZF application, the MVC Router decides which controller class to load based
on the current request's URL.  This loads a controller class at runtime, as
well as any model classes and view scripts employed by that controller. 
None of this classloading benefits from the APC opcode cache.

This limitation is PHP's Achilles Heel.  Many design patterns, and even
simpler forms of OO programming such as polymorphism, are resistant to
optimization by the opcode cache - the chief performance solution for the
language.

Rasmus wrote an article describing a "no-framework PHP MVC framework"
(http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html). 
Notice his solution doesn't use a front-controller architecture.  Instead,
he turns that architecture upside-down.  There is no router; routing is
simply a mapping of the request URL directly to the path of the view script
(you can use mod_rewrite to make URL's prettier).  Then the view script
loads any additional code it needs, using compile-time includes, which do
benefit from the opcode cache.

Do use ZF or other MVC frameworks for the benefit they give to development
and maintenance.  But don't expect the opcode cache to be a magical way to
make everything run faster.

Regards,
Bill Karwin
-- 
View this message in context: 
http://www.nabble.com/Caching-of-MVC-and-other-ZF-components-tp15576554s16154p15599812.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to