PHP会增加页面加载时间吗? [英] Does php increase a page loading time?

查看:97
本文介绍了PHP会增加页面加载时间吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上使用了php,因此它可以显示多种语言。我注意到html文件的大小减少了,因为大部分文本都被移动到了一个新的大型PHP文件,其中包含所有可用语言中的所有惯用文本(在我的例子中只有两个)。



我的问题是:以前只用必要的文本下载了一个html页面。现在下载了一个较小的html页面,但是总是包含一个大的php文件,无论html是使用更多还是更少的行。



问题:


  1. 包含php文件( include_once(file.php); require_once(file.php); )发生了什么?是否将 file.php 的内容复制到html中?它只是用来对语言处理器说:如果你需要解析一个名字,你可能想看看 file.php

  2. 什么是(速度)高效;在每个html页面的每一种语言中都有一个大php; 每个html页面只有一个php文件需要该页面所需的代码?

  3. 如果php在使用前被包含,应该是一个普通的包含在页面顶部的大部分php,最终将在html页面中使用?

  4. 最后,php是否会增加页面加载时间?

PS:任何人都试过 PHP Speedy ?它真的有用吗?是否有任何问题(兼容性)?






我发现:


  1. (检查解决方案)
  2. 两种解决方案的性能完全相同。我选择使用语言分隔文件,因为它感觉更整齐。

  3. 与上述相同,不会影响效果。


< 1)每个include / require语句都被包含/必需文件的内容替换。包含文件本身的内容正在成为执行脚本的一部分,但如果它成为HTML响应的一部分,则取决于内容本身。



2)除非你有大量的访问者几乎不会注意到包含一个大文件和几个较小文件的区别。然而,它的好做法是仅包含实际需要的部分,因为这样您可以节省Web服务器内存和资源,这可能在发生大量请求时出现问题。



< 3)它包括你的代码在哪里并不重要。出于纯粹的组织原因,尽可能在脚本开始处包含所有内容,但有时这是不可能的,这意味着您经常会看到代码包含在函数内部等。



4)与纯HTML文件相比,解析PHP文件存在一些延迟,因为该过程涉及到Web服务器扩展本身的往返,但由于内部缓存机制等原因,延迟很难找到,如果不是几乎不可能证明统计。



编辑:如果您关心您的网站性能, Google Chrome扩展程序,例如 Page Speed Speed Tracer 。它们将帮助您找出可能降低您网站性能的常见问题。



对于服务器端来说,使用代码分析器可以发现潜在的性能消耗,如高函数调用次数等。为此,您可以使用 xDebug PHP调试器 profiler和 WebGrind 来分析性能本身。


I used php on my website so it can display multiple languages. I noticed the size of the html files reduced because most of the text was moved to a new large php file, which contains all "idiomatic" text in all languages available (just two in my case).

My problem is: Previously a html page was downloaded with just the necessary text. Now a smaller html page is downloaded but a large php file is always included, whether the html uses more or less lines of it.

Questions:

  1. When a php file is included (include_once(file.php); or require_once(file.php);) what is happening? Is the content of the file.php being copied to the html? Is it just used to say to the language processor "If you need to resolve a name, you may want to look at file.php"?
  2. What is more (speed) efficient; to have one large php with every language of every html page inside; or to have one php file per html page only with the code needed by that page?
  3. Should a php be included right before being used, or should be a general include at the top of the page that gets most of the php that will eventually be used along the html page?
  4. Finally, does php increase a page loading time?

P.S: Anyone tried PHP Speedy? Does it really works? Does it have any problems (compatibility) ?


I found out:

  1. (check solution)
  2. Both solutions have exactly the same performance. I chose to separate the file by language because it feels tidier.
  3. Same as above, no impact on performance.

解决方案

1) Every include / require statement is replaced by the content of the included / required file. The content of the included file itself is becoming part of the executing script however if it will become part of the HTML response depends upon the content itself.

2) Unless you have a very large number of visitors you will hardly notice a difference between including one large file and several smaller ones. However its good practice to include only parts which are actually required because that way you are saving web server memory and resources which might present a problem in case of a large number of requests.

3) It doesn't really matter where you include your code. For pure organization reasons its good to include all the stuff right at the beginning of the script however sometimes this is not possible which means that you'll often see code included inside functions etc.

4) There is some latency involved with parsing PHP files when compared against pure HTML files because the process involves a "roundtrip" to the web server extension itself however because of the internal caching mechanisms etc. that latency is very hard to spot, if not almost impossible to prove statistically.

EDIT: If you are concerned about your web site performance a good place to start are some of the Google Chrome extensions such as Page Speed and Speed Tracer. They will help you pinpoint the usual problems that might lower your web site performance.

For the server side its always good to use code profilers to find potential performance hogs such as high number of function calls etc. For that you can use xDebug PHP debugger which comes with an excellent profiler and WebGrind to analyze the performance itself.

这篇关于PHP会增加页面加载时间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆