PHP 使用的包含数
我使用许多包含来显示我网站的小部分。使用许多包含可以吗?或者我应该减少它们(尽可能多)。包含函数还要花费多少时间?
我的主页加载速度非常慢。有什么方法可以让它加载更快。 (我的主页每天在主页上显示几乎相同的内容一个小时(并且仅在某些部分显示一些不同的数据)。我可以缓存它吗..可用于缓存的最佳解决方案是什么或我可以使用的其他方式事情更快。)
I am using many include to show small sections of my site. Is it fine to use many include or I should just reduce them (as much possible). How much more time does a include function cost?
My home page loads very slowly. What is the way to make it load faster. (My homepage shows almost same content on home page for an hour daily (and it shows some different data in some sections only). Can I cache it..what is the best solution available for caching or some other way with which i can make things faster.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果信息只持续一小时并且会被更改,那么就没有理由对这部分信息使用缓存,因为下次人们访问时,他们将获得另一条信息,而缓存的信息就被浪费了。
而且,我认为当前页面中包含文件和包含文件内容之间没有太大区别,因为它们的执行方式都是类似的。使用
include()
只是让你的代码看起来更干净,更容易控制和维护。现在转向为什么你的主页加载太慢的问题,我认为这不是你的
include()'s
的问题,但可能是你处理数据的方式有问题。正如有人在您的帖子中评论的那样,请使用 Xdebug 来查找导致主页速度变慢的原因。祝你好运。
If the information only lasts for one hour and will be changed, then it's no reason using cache for that section of information, because the next time people visit, they will get another information and the cached one goes waste.
And, I don't think there is much difference between including a file and including a file's content in the current page, since they will all be executed similarly. The use of
include()
just makes your code look cleaner, easier to control and maintain.Turning now to the question why your homepage loads too slow, I think it's not a problem with your
include()'s
, but could be a problem with your way of processing data. As somebody commented in your post, use Xdebug to find what makes your homepage slow.Good luck.
也许这个问题的答案可以帮助您:
PHP include(): 文件大小和大小性能
Maybe the answer to this question helps you:
PHP include(): File size & performance
如果内容每小时更新一次,为什么不每小时创建一个静态 html(很容易通过 php 完成),这样,只有静态 html 被读取并加载给用户,而不是在生成时生成网络请求。
编辑:
您创建一个 php 脚本,它将生成一个像 index.html 这样的文件,并用 html 代码填充它。然后每小时执行该 php 脚本。这可以通过使用 CRON 作业来实现。如果您想了解有关其中任何一个的更多信息,请询问有关该主题的另一个问题。
If the content is updated on an hourly basis, why don't you create a static html (cam easily be done by php) upon an hourly basis, so that, only that static html is read and loaded to users instead of being generated upon web requests.
EDIT:
You create a php script that will generate a file like index.html and fill it with html code. Then you execute that php script every hour. This can be achieved by using CRON jobs. If you want more information on either of those then please ask another question specified on that subject.