如何提高 PHP 中“include()s"的性能? [英] How can I improve the performance of 'include()s' in PHP?

查看:43
本文介绍了如何提高 PHP 中“include()s"的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 1.9MB 的 PHP 库,我将它包含在脚本的开头.它包含我的网站所需的所有数据库对象、方法等.每次包含它需要 0.1s 到 0.3s.

I have a 1.9MB PHP library that I am including at the beginning of my scripts. It contains all of my database objects, methods, etc necessary for my website. It takes 0.1s to 0.3s to include it each time.

我使用 eAccelerator 来缓存这个文件的字节码.我还能做些什么来优化这个包含"的性能?

I use eAccelerator to cache the bytecode of this file. What else can I do to optimize the performance of this 'include'?

推荐答案

将其拆分为模块并仅在需要时加载块.我认为这是真正提高性能的唯一方法,我遇到过同样的情况,只有这样才能解决它.在我看来,要包含的代码太多了.我敢打赌,您不需要在每个上下文中都需要 1.9MB 的代码.

Split it into modules and load the chunks only when needed. I think that is the only way to really improve performance, I have been in the same situation and only that solved it. It's a lot of code to include, in my mind too much. I'll bet you a beer that you do not need all 1.9MB of code in every context.

这篇关于如何提高 PHP 中“include()s"的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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