开发者

Reduce number of included files

My application based on Zend Framework and Doctrine includes > 300 files on each request. They are mostly the same files.

This is a quite huge overhead. Partially solved by Zend_Cache (and Memcache), but not all the pages may be cached.

  • How to reduce this number? How to speed up?

Doctrine has an option to compile the needed files which seems quite rational for production server and final version of the app.

My p开发者_如何学Golan is to compile other libraries too (I have already stripped all require_once's).

  • Are there any tools for this task? Maybe some cache drivers do it automatically? How to set them up?


The overhead of php file inclusions can usually be countered with an opcode cache such as APC, an extension available through pecl. Opcode caches generally work by caching the compiled bytecode so that the overhead of reading and parsing the source is only incurred on the first request. This will greatly negate the need or benefit of any source compilation on your php files.


Best option is to use APC or Zend_Accelerator. But still you can make these "compilation" scripts that merge classes together into one file. That lowers the required IO to minimum. Unfortunately, you also need to rewrite the autoloading process so that it looks into appropriate file. You can usually condense common classes together (Zend_Form + Elements + Decorators, frequently used validators, Request + Response + Router + Controller, Zend_Db + adapters + Zend_Db_Select, etc.). Mainly the classes always used on each request can be easily condensed and included manually in one file. Best way is to add debug call, that save all included files (http://www.php.net/get_included_files) into DB and then:

SELECT * FROM files GROUP BY filename WHERE COUNT(filename) = $numOfRequests

All the files in the result can be safely merged into a single file and included before bootstraping :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜