Breaking up a page and use require in PHP

十年热恋 提交于 2020-01-06 05:15:09

问题


I´m working on a new web page, and the pages gets extremly long with thousands of rows. So I´m planning on breaking up the page´s different sections into several pages and then display them using require_once() or require() in the main page. My question is if this will affect the speed when the pages load? It feels that way since it has to open up and load several pages. But maybe I´m wrong?


回答1:


Don't worry about it. The difference is rarely important. require_once() is slower than require() if you need to choose.

Install apc (Alternative PHP Cache) and require() is just as fast as including it directly (but require_once() is not as good).

http://pecl.php.net/package/APC




回答2:


  1. Don't think about performance until you have actual performance problem. Just split it as is most convenient for maintenance (i.e. split those pieces that will be reused on multiple pages).
  2. The other processing probably takes much more time than any possible penalty incurred by using require(). If not, you shouldn't be using PHP in the first place (i.e. if it's otherwise static, use server-side includes).


来源:https://stackoverflow.com/questions/7008303/breaking-up-a-page-and-use-require-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!