Wordpress、Joomla、vBulletin 等大型 PHP 应用程序为何运行得如此之快?

发布于 2024-11-19 12:14:36 字数 97 浏览 1 评论 0原文

如果你仔细想想,我提到的所有应用程序都有数万行,有的有数十万行。然而,尽管每个请求都必须通过 PHP 解释器运行大量代码,但它们的占用空间似乎相当小。

这是为什么?

If you think about it, all of the applications I mentioned have tens of thousands of lines of side, some hundreds of thousands. Yet they seem to have a fairly light footprint despite the huge amounts of code that must be run through the PHP interpreter for each and every request.

Why is that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不奢求什么 2024-11-26 12:14:36

如果你仔细想想,我提到的所有应用程序都有数十个
侧面有数千行,有的有数十万行。

这实际上相当小。有些项目有数百万甚至数千万行代码。

然而,尽管它们的体积巨大,但它们的足迹似乎相当轻。
每个项目必须通过 PHP 解释器运行的代码量
以及每一个请求。

通常,代码仅解析一次,并将生成的字节码存储在缓存中(例如 Xcahe、APC)。因此,不必对每个请求都解释所有这些行。

此外,并非每个请求都需要执行所有代码。

通常,Web 应用程序响应所需的大部分时间是数据库访问和数据传输(从数据库到 PHP,以及从 PHP 通过 Web 服务器到应用程序)。

If you think about it, all of the applications I mentioned have tens
of thousands of lines of side, some hundreds of thousands.

That's actually fairly small. There are projects out there with millions, even tens of millions of lines of code.

Yet they seem to have a fairly light footprint despite the huge
amounts of code that must be run through the PHP interpreter for each
and every request.

Often the code is only parsed once and the resulting bytecode stored in a cache (e.g. Xcahe, APC). So, all those lines do not have to be interpreted every request.

Also, not all the code needs to be executed every request.

Usually, the bulk of the time it takes a web application respond is database access and data transfer (either from the database to PHP, and from PHP though the webserver to your application).

等待我真够勒 2024-11-26 12:14:36

这不在于数量,而在于质量。我可以阅读四行代码,这比 Wordpress 页面需要更多的时间来执行。

这都是关于良好的优化

但是,您列出的那些应用程序对 RAM 和内存来说并不轻松。 CPU使用率

It's not about quantity, but quality. I can read four lines of codes which would take more time to execute than Wordpress page.

It's all about good optimalization

However, those applications you listed aren't light to RAM & CPU usage

故事未完 2024-11-26 12:14:36

简而言之,它们不是与其他技术相比,而是与人类的速度相比:当然,它们很快。

另一件需要考虑的事情是,PHP 解释器不会针对每个请求运行 Wordpress 目录中的所有代码。 Apache 将从单个 PHP 页面开始,然后根据需要拉入其他页面。然后,所有这些页面都会被即时解释,直到程序获得所需的结果,因此有时页面上的大部分代码都没有被利用,这使得占用空间更小。

此外,根据您实际运行 PHP 的方式,也会产生很大的差异。如果您处于其中一种 CGI 模式,则每个请求都会启动 PHP 解释器的一个实例,而 PHP 作为 Apache 模块已将其预加载到内存中,因此不必进行前端加载。

The short answer is that they don't in comparison to other technologies, but compared to how quickly a human could do it: sure, they're fast.

Something else to consider is that the PHP interpreter isn't running through all the code in the Wordpress directory for every request. Apache is going to get it started with a single PHP page which then pulls in other pages on demand. All of those pages are then interpreted on the fly until the program has the results it needs, so sometimes a good bit of the code on a page is not utilized, which keeps the footprint smaller.

Also, depending on the way you're actually running PHP makes a big difference. If you're in one of the CGI modes, each request boots up an instance of the PHP interpreter, whereas PHP as an Apache module has it preloaded into memory already so it doesn't have to do that frontloading.

贪恋 2024-11-26 12:14:36

我个人并不认为它们跑得快。在大多数 WordPress 网站上渲染页面几乎需要半秒 - 但其中许多网站的服务器上的 CPU 能够每秒计算数十亿个周期。

这并不是说 PHP 本身就那么慢。我的应用程序(基于框架构建)通常仅使用 3MB RAM(其中只有 600kb 来自我的代码)运行大约 50ms。

I don't personally find that they do run fast. It takes almost half a second to render a page on most wordpress sites - yet many of them are on a server with a CPU able to calculate billions of cycles every second.

That's not to say PHP its self is that slow. My applications (built on a framework) generally run in about 50ms using only 3MB of RAM (and only 600kb of that is from my code).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文