You are here

drupal performance:为何减小module文件大小能加快速度?

g089h515r806 的头像
Submitted by g089h515r806 on 星期六, 2010-05-15 15:24

在drupal的handbook:http://drupal.org/node/146172 上有这么一句话

Any module that has more than ~50 lines of code for page handler functions (including form handling functions if applicable) should split them off into a separate file. That reduces the overhead for PHP when loading modules, and therefore speeds up every single request on the site.

大意就是说,Drupal对于每个完整的页面请求,都会加载所有已经启用了的模块的module文件,如果有一个模块,它的*.module文件中,有多于50行的代码是用来处理页面回调的,那么.module文件中的这样的代码,就应该被独立到单独的inc文件中,inc文件分两种,一种是mymodule.admin.inc,另一种是mymodule.pages.inc.如果不是访问这个模块提供的页面回调,那么就不会加载这个模块的Inc文件,通过将模块自身的内部处理放置在inc文件中,就会减小.module文件的大小,从而降低每次页面请求,所加载的总文件大小。间接的实现了缓加载技术,进而提升了性能,这是Drupal6在性能上的一个改进。

我今天刚给朋友讲解的,为什么分出来inc文件,它的好处。顺便纠正一下网络上的上面这段话的译文。

 

Drupal版本: