在我需要的 php 文件中包含所有函数还是只包含我需要的函数? [英] Include all functions in the php file I need or just the functions I need?

查看:41
本文介绍了在我需要的 php 文件中包含所有函数还是只包含我需要的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要做的.

  1. 第一个选项是写每个每个函数在不同的php文件中一个,然后将它们全部包含在一个名为 include 的 php 文件functions.php 和每当我创建一个新页面,让我们说 index.php 我只需包含functions.php";

  1. The first option is to write each function in different php file each one and then include all of them in a php file that is called include functions.php and whenever I create a new page , let's say index.php I just include "functions.php";

为什么我需要这样做?因为我只需要包含一个文件,所有功能都将包含在内.现在问题可能是服务器负载.我不确定有多少未调用的函数会影响性能.

Why do I need to do that? Because I'll just have to include only one file and all the functions will be included. Now the problem probably will be the server load. I'm not sure how much uncalled functions affect the performance.

第二个选项是重新创建我需要的文件,将它们组合起来,然后每当我需要一个函数时就调用它.这样做的缺点是我需要做更多的工作来进行分类,而且我必须包含很多文件

The second option is to create again the files I need, team them up and then whenever I need a function just call it. The drawback of this is that I'll have more work to do in order to categorize and I'll have to include a lot of files

所以我想问一下,第一个选项是否增加了我必须转到第二个选项的 cpu 和内存负载?第一种方式是否存在任何性能问题,或者 php 根本没有解析未使用的函数?

So I want to ask, does the first option increase the cpu and memory load that much that I have to go to the second one? Are there any performance issues with the first way or the functions that are not being used are not parsed at all by the php ?

推荐答案

磁盘是服务器中最慢的部分,因此在这种情况下,变体1 个文件中的所有功能"理论上会给您带来更多的性能.

Disk is a slowest part of the server, so in this case variant "all functions in 1 file" will give you little more performance, theoretically.

但我不建议你创建functions.php",更好的方法是 面向对象.使用方法创建(对象),使用autoloaders 和 PSR-0 标准,你会忘记包括"和需要".

But I don't recommend you to create "functions.php", better way is OOP. Create classes (objects) with methods, use autoloaders and PSR-0 standard and you will forget about "include" and "require" at all.

这篇关于在我需要的 php 文件中包含所有函数还是只包含我需要的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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