PHP 作为 CGI 如何处理内存?
当使用 Apache 运行 PHP 时,我知道每个请求都会加载 php 核心和所有库。但是,使用 PHP CGI、FastCGI 或使用 PHP-FPM,php 进程在重新启动之前通常会持续 500-1000 个请求。
在此期间,它如何处理加载的 PHP 类或库?
假设我有一个加载大型库的文件,它会在每个请求时加载(然后转储)大型库还是为我传递的每个新请求保持加载?
我所说的“已加载”是指包含(并解析)类,但不创建任何对象。
APC 如何发挥这一作用?
When running PHP with Apache I know that the php core and all libraries are loaded for each request. However, with PHP CGI, FastCGI, or using PHP-FPM the php process persists for generally 500-1000 requests before it's restarted.
During that time, how does it handle loaded PHP classes or libraries?
Lets say I have a file that loads a massive library, will it load (then dump) the large library every request or keep it loaded for each new request I pass it?
By "loaded" I mean the classes are included (and parsed) but no objects are created.
How does APC play into this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 FCGI(PHP-FPM 也是 FCGI),只有 php 二进制文件及其二进制库保留在内存中。 PHP 用户代码没有。
把他们踢开,让他们根据新的要求接受新的。您可以通过设置全局变量轻松测试它们是否在新请求开始时消失。
因此,您(粗体)问题的答案是让我们直接回答:是的,它会根据每个请求加载和转储,否或!:)
APC 也这样做。我需要研究一个链接,有一个用 PHP 编写的网络服务器,因此它可以将所有内容保存在内存中。为您提供真正的速度,但是您的应用程序代码必须正确处理更改后的请求逻辑。
For FCGI (PHP-FPM is FCGI as well), only the php binary and it's binary libraries stay in memory. The PHP user-code does not.
Kicks them off, get's them new on a new request. You can easily test that by setting global variables, they are gone at the beginning of the new request.
So the answer to your (bold) question is Let's straight-forward answer: Yes, it get's loaded and dumped per each request, no or! :)
APC does the same. I need to research a link, there is a webserver written in PHP so it can keep everything in memory. Give's you the real speed, however your applications code must properly deal with the changed request logic then.