2013-07-18 19:54
浏览 14

php是否包含减少页面加载? [关闭]

I was just wondering that separating header, navigation, layout, sidebar, footer into apart pages and with php include function managing them just to be able to reduce time of work is bad approach? Bad influence on performance?

图片转代码服务由CSDN问答提供 功能建议

我只是想知道将标题,导航,布局,侧边栏,页脚分隔成分开的页面并使用php包括功能管理 他们只是为了能够减少工作时间是不好的方法? 对性能有不良影响?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • douwo1862 2013-07-18 19:57

    This will have such a minimal impact (if any) on overall page load performance that it is not worth considering until you are probably serving millions of requests per minute, at which point you would probably have already switched to a compiled language.

    This should never be a determining design factor in PHP unless you are just doing something silly like breaking your code up into thousands of includeable files which need to be loaded.

    Do what makes your code more maintainable.

    打赏 评论
  • dpecb06062 2013-07-18 19:56

    no, it's always additional file open operation but if it's just separated header/footer/sidebar - you really have nothing to worry about ;)

    打赏 评论
  • douqiang1910 2013-07-18 19:56

    The processor load/time to include a page is so small that you won't notice it. It doesn't even register on my machine - and it is a single CPU with a single core, not a fancy web server.

    打赏 评论
  • dongzi0850 2013-07-18 19:57

    Including a file is definitely a performance hit*, but it will be incredibly tiny and miniscule compared to the time saved in developing and maintaining nicely modularized code.

    * The performance hit will be noticeable if you include thousands of files. If you're including a few files, the extra CPU/IO cycles it takes won't be noticeable.

    打赏 评论
  • duanbicheng3345 2013-07-18 20:01

    Of course the hit performance is not that important with this kind of include but be careful to not include too many script because making an I/O has always a cost.

    You can use some cache like APC to be sure that the code does not make to many I/O.

    In this case you will not worry but when you'll write more complicated code and I'm sure you will :) you will find it good advice I hope.

    Just have a look at thi bench on an apache server.

    When you call a simple echo "hello world";

    Total transferred: 3470000 bytes 
    HTML transferred: 120000 bytes 
    Requests per second: 2395.73 [#/sec] (mean)
    Time per request: 4.174 [ms] (mean) 
    Time per request: 0.417 [ms] (mean, across all concurrent requests) 
    Transfer rate: 811.67 [Kbytes/sec] received 

    So always think about performance hit even if the query is simple because PHP does a lot of stuff to print data.

    打赏 评论

相关推荐 更多相似问题