与小型专用php脚本相比,单片PHP编码的优点/缺点是什么? [英] What are the advantages/disadvantages of monolithic PHP coding versus small specialized php scripts?

查看:99
本文介绍了与小型专用php脚本相比,单片PHP编码的优点/缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从历史上看,我一直使用整体方法进行PHP编码.

I have historically used a monolithic approach to PHP coding.

也就是说,我编写了一个index.php,平均大小为70k-250k,并使用

That is, I write one index.php, with an average size of 70k-250k, and use

mod_rewrite

转动其余的

REQUEST_URI 

将参数传递到index.php中,以控制正在发生的事情.

into parameters passed into the index.php to control what is happening.

替代方法是编写许多小型php脚本,每个脚本专门用于特定目的.我认为我的一些更活跃的Ajax脚本可能会从中受益.

The alternative would be to write many small php scripts, each specialized to a particular purpose. I'm thinking that some of my more active ajax scripts may benefit from this.

让我陷入这一思考过程的一件事是,我不知道如何使用包含,尤其是条件包含会影响操作码缓存的性能.

One thing that has kept me in this thought process is I don't know how using includes, especially conditional includes would affect the performance of the opcode cache.

由于对此我的偏执,我通常尽量避免包括所有内容,但这会导致代码重复或保持整体状态.

I have generally avoided includes altogether if possible due to my paranoia about this, but this results in either duplicating code, or staying monolithic.

无论如何,我在使用mod_rewrite时,两种方法之间的转换应该很简单.

As I'm using mod_rewrite anyway, converting between the two methodologies should be simple.

期待您的评论.

我的目标应用程序之一当前每秒处理80-100个页面命中(我得到了一些不错的硬件).其中大多数是ajax请求.一切正常,而且很敏捷,但是我已经发展为一个无需批判的php程序员,并且需要它.

One of my target apps currently handles 80-100 page hits per second (I got some decent hardware). Most of those are ajax requests. Everything works and is snappy, but I've developed as a php programmer without critique and need it.

推荐答案

模块化代码更易于理解和维护.巨大的整体代码库可能变得像纸牌屋.实际上,它工作得很好,但是更改任何较低的元素都变得不可能.如果将代码分成清晰的抽象,进行更改会容易得多,而且一旦添加开发人员,就可以避免噩梦.

Modular code is easier to understand and maintain. A huge monolithic codebase can become like a house of cards. It works just fine in practice, but changing any of the lower elements becomes impossible. If you split up your code into clear abstractions, it can be much easier to make changes and you'll save yourself a nightmare if you ever add developers.

这篇关于与小型专用php脚本相比,单片PHP编码的优点/缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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