在PHP中使用自动加载类时是否存在性能问题? [英] Are there performance downsides while using autoloading classes in PHP?

查看:409
本文介绍了在PHP中使用自动加载类时是否存在性能问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我通过在我的网站的每个页面上包括一个all.inc.php文件加载所有我的类,这个文件然后继续包括所有的配置,类,函数等,我将使用整个网站。

Currently I load in all my classes by including a "all.inc.php" file on every page of my site, this file then goes on to include all the config, classes, functions, etc. that I will use on the whole site.

我的问题是,我经常使用的类只与网站的某些页面/部分,所以经常我包括一堆类

My issue with this is that often I use classes that only pertain to certain pages/sections of a website, so often I am including a bunch of classes at the start of the page which will not be used.

很明显,自动加载类会解决这个问题,所以我的问题是,自动加载类会给我一个表现不佳因为服务器然后必须检查文件是否存在?如果有一个缺点,那么这种下降比必须包括一些可能不会在页面上使用的类吗?或者差异是否可以否定?

Obviously autoloading the classes would fix this issue, so my question is, would autoloading the classes give me a performace downside as the server then has to check if a file exists? And if there is a downside, then is this downside worse than having to include a number of classes that may not get used on the page? Or is the difference negatable?

推荐答案

本文包含一些信息和基准: PHP自动加载性能。结论:

This article has some information and benchmarks: PHP autoload performance. Conclusion:


自动加载不会显着降低性能。 Include_path查找,从磁盘读取和解析PHP脚本所需的时间比裸自动加载逻辑成本更长。

Autoloading does not significantly degrade performance. Include_path lookup, reading and parsing PHP scripts from disk takes much longer time than that bare autoloading logic costs.

这篇关于在PHP中使用自动加载类时是否存在性能问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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