包含不必要的php文件会减慢网站速度吗? [英] Will including unnecessary php files slow down website?

查看:134
本文介绍了包含不必要的php文件会减慢网站速度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题可能会促使某些人几乎立即说出肯定的YES或NO,但请继续阅读...

The question might prompt some people to say a definitive YES or NO almost immediately, but please read on...

我有一个简单的网站,其中有30个php页面(每个都有一些php服务器端代码+ HTML / CSS等...)。没有复杂的等级,没有。只有30页。

I have a simple website where there are 30 php pages (each has some php server side code + HTML/CSS etc...). No complicated hierarchy, nothing. Just 30 pages.

我还有一套纯后端的php文件 - 那些有代码保存数据库,进行身份验证,发送电子邮件,处理订单等。这些将被这30个内容页面重用。

I also have a set of purely back-end php files - the ones that have code for saving stuff to database, doing authentication, sending emails, processing orders and the like. These will be reused by those 30 content-pages.

我有一个主php文件,我发送了一个参数。这指定了需要这30个文件中的哪一个,并且它包含适当的内容页面。但是每一个都可能需要包含可变数量的后端文件。例如,一个内容页面可能不需要后端,而另一个可能需要数据库代码,而其他内容可能需要电子邮件,数据库和身份验证代码等...

I have a master php file to which I send a parameter. This specifies which one of those 30 files is needed and it includes the appropriate content-page. But each one of those may require a variable number of back-end files to be included. For example one content page may require nothing from back-end, while another might need the database code, while something else might need the emailer, database and the authentication code etc...

我猜任何后端页面都是必需的,可以包含在相应的内容页面中,但路径中的一个小变化我必须编辑数十个文件。在主php文件中检查请求哪个内容页面(switch-case类型的东西)并包含相应的后端文件将太麻烦了。同样,如果单个路径发生变化,我必须进行许多更改。

I guess whatever back-end page is required, can be included in the appropriate content page, but one small change in the path and I have to edit tens of files. It will be too cumbersome to check which content page is requested (switch-case type of thing) and include the appropriate back-end files, in the master php file. Again, I have to make many changes if a single path changes.

懒惰,我在主文件中包含所有后端文件,以便没有内容页面可以请求某些内容这不包括在内。

Being lazy, I included ALL back-end files inthe master file so that no content page can request something that is not included.

第一个问题 - 这是一个好习惯吗?如果它完全是由任何人完成的。

First question - is this a good practice? if it is done by anyone at all.

第二,是否会出现性能问题或由于我而导致的任何问题,包括所有后端文件,无论是否需要它们吗?

Second, will there be a performance problem or any kind of problem due to me including all the back-end files regardless of whether they are needed?

编辑

该网站的价格在3000到4000之间每天访问。

The website gets anywhere between 3000 - 4000 visits a day.

推荐答案

您应该进行基准测试。使用不同的包含执行相同页面的时间。但我想这对30个文件没什么区别。

You should benchmark. Time the execution of the same page with different includes. But I guess it won't make much difference with 30 files.

但你可以节省时间并启用 APC (它是一个PECL扩展,所以你需要安装它)。它将缓存文件的已解析内容,这将显着加快速度。

But you can save yourself the time and just enable APC in the php.ini (it is a PECL extension, so you need to install it). It will cache the parsed content of your files, which will speed things up significantly.

BTW:懒惰没有问题,它甚至是美德;)

BTW: There is nothing wrong with laziness, it's even a virtue ;)

这篇关于包含不必要的php文件会减慢网站速度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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