pbrodka
pbrodka

Reputation: 1137

Caching always loading files in PHP

In my index.php file I always load some classes used later. From profiler it states it sometimes can take about 20% of entire code. Is there any improvement that can make this process faster?

I would try to make this list of classes shorter, but app is very big and checking all dependencies will be costly.

Upvotes: 0

Views: 311

Answers (3)

Sean McSomething
Sean McSomething

Reputation: 6507

While using an opcode cache (such as APC) will reduce the impact of loading/parsing/compiling the class, you'll still be loading them all on every page load & doing whatever initialization accompanies a require_once() call. If you were to set up an autoload function then the classes won't be loaded until your code actually needs to use them. There's a little overhead involved in using a class autoloader but it makes the code easier to maintain.

As always, YMMV, so benchmark your application to see if it's worthwhile in your case.

Upvotes: 2

Eran Galperin
Eran Galperin

Reputation: 86805

Op-code caches such as APC and eAccelerator store a compiled version of your scripts in a cache. This dramatically reduces memory usage and loading time for frequently used static scripts.

Upvotes: 2

Zoredache
Zoredache

Reputation: 39583

You might want to look at apc php.net/apc

Upvotes: 0

Related Questions