一个大功能的php文件值得关注吗? [英] is a big functions php file a concern?

查看:39
本文介绍了一个大功能的php文件值得关注吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web应用程序,并且正在使用一个名为functions.php的文件,其中存储了与我的应用程序相关的所有功能,当前该文件包含约1500行代码以及30多个函数.

I'm developing a web application and I'm using a file called functions.php in which I stored all the functions related to my application, currently the file has about 1500 lines of code with over 30 functions.

我想知道这是否是一个问题,调用函数时是否会减慢该过程?我应该制作其他文件以将某些功能移到那里吗?

I was wondering if it is a problem, could it slow down the process when calling functions? Should I make other files to move some of the functions there?

推荐答案

在大多数情况下,.php脚本中的行数几乎不会像代码本身那样影响程序的速度.如果执行时间是您的第一要务,那么优化代码应该是您的第一要务.从最常调用的功能开始,并确保其中的代码尽可能紧密.

In most cases, the number of lines in the .php script isn't going to affect the speed of the program nearly as much as the code itself. If execution time is your number one concern, then optimizing your code should be your number one priority. Start with the functions that are called the most, and make sure the code there is as tight as possible.

将功能拆分为不同的文件在技术上会使脚本 slower 变慢,因为解释器将必须执行磁盘I/O来解析文件.但是速度的打击将是无穷的,所以我认为将它们拆分可能从长远来看会节省时间,因为如果您不总是盯着相机看,调试和优化会更容易.巨大的文件,其中包含30个功能.

Splitting the functions up into different files would technically make the script slower since the interpreter would have to do disk I/O to parse the files. But the speed hit would be infinitesimal, so I'd argue that splitting them up might save time in the long run since it'll be easier to debug and optimize if you're not always staring down a huge file with 30 functions in it.

最后,如果您必须在应用中使用大量的.php文件,则可能需要使用

Finally, if you do have to use a bunch of huge .php files in your app, you might want to look into using something like Zend that will compile your scripts on the server.

这篇关于一个大功能的php文件值得关注吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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