包括PHP文件对性能有多大影响

包括PHP文件对性能有多大影响

本文介绍了包括PHP文件对性能有多大影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题几乎说明了一切,我正在做一个大型项目,其中大多数对php include()的调用在100到150个文件之间. php平均花费的时间在150到300毫秒之间.我想知道其中有多少是由于包含PHP脚本引起的?我一直在考虑运行一个脚本,该脚本检查最常访问的文件是否有特定的调用,并将它们合并到一个文件中以加快处理速度,但是就我所知,这几乎没有影响.

Question pretty much states it all, I am working on a large project where most calls to php include() between 100 and 150 files. On average the time php takes is between 150 and 300 ms. I'm wondering how much of this is due to including PHP scripts? I've been thinking about running a script that checks most accessed files for particular calls and merge them into one file to speed things up, but for all I know this has zero impact.

我应该注意,我使用的是APC,但我并不完全了解APC在后台执行的操作,但是我想它可能已经以某种方式缓存了我的文件,所以文件的数量并没有太大的不同吗?

I should note that I use APC, I'm not fully aware of what APC does in the background, but I would imagine it might already cache my files somehow so the amount of files doens't really make a big difference?

将感谢您对该主题的任何投入.

Would appreciate any input on the subject.

当然,300毫秒不是很多,但是如果我可以说100甚至50毫秒,那将是一个很大的提升.

Of course, 300ms isnt much, but if I can bring it down to say, 100 or even 50ms, thats a significant boost.

为澄清起见,我正在谈论通过php include/require加载文件.

To clarify I am talking about file loading by php include / require.

推荐答案

文件加载是一件棘手的事情.就像其他人所说的,唯一可以肯定的方法就是做一些基准测试.但是,以下一些通用规则仅适用于PHP加载,不适用于具有fopen的文件:

File loading is a tricky thing. As others have said, the only sure fire way to tell is to do some benchmarks. However, here are some general rules that apply only to PHP loading, not files with fopen:

  • APC将其操作码缓存存储在共享内存中,因此您将在第一次加载时受到打击,但不会在随后的加载中遭受打击.
  • includeinclude_once(以及它们的require表亲)实际上很重.以下是一些提高速度的提示:
    • 使用文件的绝对路径(避免使用诸如../foo.php之类的相对路径)
    • _once函数都需要检查以确保不通过符号链接也包含该文件,因为符号链接可以产生指向同一文件的多个路径.这是非常昂贵的. (请参阅下一点)
    • APC will store its opcode cache in shared memory so you will take a hit on the first load but not subsequent loads.
    • include and include_once (and their require cousins) are actually quite heavy. Here are some tips to improve their speed:
      • Use absolute paths to your files (avoid relative paths like ../foo.php)
      • Both the _once functions need to check to make sure that the file wasn't also included via a symbolic link since a symbolic link can produce multiple paths to the same file. This is extremely expensive. (see next point)

      总体而言,这取决于您的硬盘速度.但是与完全不加载文件或不从RAM加载文件相比,文件加载的速度令人难以置信.

      Overall it is dependent on your hard disk speed. But compared to not loading a file at all or loading it from RAM, file loading is incredible slow.

      我希望能有所帮助.

      这篇关于包括PHP文件对性能有多大影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:20