Apache 的 mod_php 还是 FastCGI?哪个对 Wordpress 有好处?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1405656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache's mod_php OR FastCGI? Which is good for Wordpress?
提问by rahul286
I have basic idea about running PHP in different configurations like mod_php, cgi, FastCGI, etc.
我对在不同的配置中运行 PHP 有基本的想法,比如 mod_php、cgi、FastCGI 等。
In my findings and test I found FastCGI is slightly better. I like FastCGI's support for SuEXEC most. Wait I do not want to get into benchmarking business here again. If you surf web, you will find people proving one way is faster than another in terms of number of requests handled per second. Well its good metrics but I am interested in different factors and here are my questions...
在我的发现和测试中,我发现 FastCGI 稍微好一些。我最喜欢 FastCGI 对 SuEXEC 的支持。等等,我不想再在这里进行基准测试了。如果您在网上冲浪,您会发现就每秒处理的请求数量而言,人们证明一种方式比另一种方式快。嗯,它的指标很好,但我对不同的因素感兴趣,这是我的问题......
- Which method of running PHP consumes less memory?
- Also which method consumes memory nearly constant. I see with mod_php my servers memory usage fluctuating between 300MB and 800MB, every few seconds.
- But with FastCGI, first response from server comes very late. I see with FastCGI there is an initial delay per webpage request. Once first response from server arrives, other items like images, css, js loads pretty faster.
- Is it OK to run mix of both? I have 5 sites on dedicated server. Is it ok if I run few with mod_php and rest with FastCGI?
- I am sure that my server goes down mostly because of improper memory usage by mod_php. I checked all scripts. Is there any way to make sure memory consumption on server remains nearly constant?
- Does complexity of .htaccess affects memory usage significantly? If yes, can it be a single reason to make server run out of memory?
- Does apache MPM prefork/worker settings affect memory consumption? Do they affect mod_php and FastCGI mode equally?
- When I run "top" command, I see apache (httpd) consuming memory around 40MB. There are many instances of httpd running. Also in addition to that FastCGI forks some processes of similar size. What is normal memory size for httpd process?
- As I am running Wordpress on all of our sites, which will be good way in that context?
- Does FastCGI/SuExec works fine with APC? Do I need to reconfigure APC to work with SuEXEC and FastCGI.
- 哪种运行 PHP 的方法消耗的内存更少?
- 还有哪种方法消耗的内存几乎不变。我使用 mod_php 看到我的服务器内存使用量每隔几秒在 300MB 和 800MB 之间波动。
- 但是使用 FastCGI,来自服务器的第一个响应来得很晚。我看到 FastCGI 有每个网页请求的初始延迟。一旦来自服务器的第一个响应到达,图像、css、js 等其他项目的加载速度会更快。
- 两者混合运行可以吗?我在专用服务器上有 5 个站点。如果我用 mod_php 运行很少并用 FastCGI 休息可以吗?
- 我确信我的服务器宕机主要是因为 mod_php 的内存使用不当。我检查了所有脚本。有什么方法可以确保服务器上的内存消耗几乎保持不变?
- .htaccess 的复杂性是否显着影响内存使用?如果是,是否是导致服务器内存不足的一个原因?
- apache MPM prefork/worker 设置会影响内存消耗吗?它们对 mod_php 和 FastCGI 模式的影响是否相同?
- 当我运行“top”命令时,我看到 apache (httpd) 消耗了大约 40MB 的内存。有很多 httpd 正在运行的实例。此外,FastCGI 还派生了一些类似大小的进程。httpd 进程的正常内存大小是多少?
- 当我在我们所有的网站上运行 Wordpress 时,在这种情况下哪种方式比较好?
- FastCGI/SuExec 在 APC 上工作正常吗?我是否需要重新配置 APC 以使用 SuEXEC 和 FastCGI。
Please note, I am less interested in surviving against DIGG or traffic spikes. I want a way which can make server stable and predictable.
请注意,我对抵御 DIGG 或流量高峰的生存不太感兴趣。我想要一种可以使服务器稳定且可预测的方法。
Sorry if I am confusing but I am really in mess. I have 512MB physical RAM, 400MB Swap and my server is running out of memory like crazy. Average memory requirement is around 350MB, it just memory usage spikes makes memory unavailable for few seconds and if few extra hits received in those few second window, apache crashed while mysql and all other fellas keep running fine.
对不起,如果我感到困惑,但我真的一团糟。我有 512MB 物理 RAM,400MB Swap,我的服务器快用完了内存。平均内存需求大约为 350MB,它只是内存使用高峰使内存在几秒钟内不可用,如果在这几秒钟的窗口中收到的额外命中很少,apache 就会崩溃,而 mysql 和所有其他人保持正常运行。
Please help me out guys. I am not gonna buy more RAM or hardware. I am damn sure that problem is in my configuration. Sorry if I sound arrogant or ignorant.
请帮帮我吧伙计们。我不会购买更多的内存或硬件。我他妈的确定问题出在我的配置中。对不起,如果我听起来很傲慢或无知。
回答by yhager
Which method of running PHP consumes less memory?
哪种运行 PHP 的方法消耗的内存更少?
I assume that per PHP-processed request they are more or less the same. But if you have mod_php loaded into apache serving images too, then I assume your memory footprint will be higher due to serving static files.
我假设每个 PHP 处理的请求或多或少是相同的。但是,如果您也将 mod_php 加载到 apache 服务图像中,那么我认为由于提供静态文件,您的内存占用量会更高。
Also which method consumes memory nearly constant. I see with mod_php my servers memory usage fluctuating between 300MB and 800MB, every few seconds.
还有哪种方法消耗的内存几乎不变。我使用 mod_php 看到我的服务器内存使用量每隔几秒在 300MB 和 800MB 之间波动。
You can make both pretty constant. If you carefully set MaxClients, MinSpareServers and MaxSpareServers, you pretty much can tell how many processes are running. If you also set memory_limit within your PHP config, you can calculate how much memory you need. You can do the same for fcgi too, since you can decide how many processes are running.
你可以让两者都非常稳定。如果您仔细设置 MaxClients、MinSpareServers 和 MaxSpareServers,您几乎可以知道有多少进程正在运行。如果您还在 PHP 配置中设置了 memory_limit,则可以计算出您需要多少内存。你也可以对 fcgi 做同样的事情,因为你可以决定有多少进程正在运行。
But with FastCGI, first response from server comes very late. I see with FastCGI there is an initial delay per webpage request. Once first response from server arrives, other items like images, css, js loads pretty faster.
但是使用 FastCGI,来自服务器的第一个响应来得很晚。我看到 FastCGI 有每个网页请求的初始延迟。一旦来自服务器的第一个响应到达,图像、css、js 等其他项目的加载速度会更快。
This doesn't make sense. I am not sure why it happens in your case.
这没有意义。我不确定为什么会在你的情况下发生。
Is it OK to run mix of both? I have 5 sites on dedicated server. Is it ok if I run few with mod_php and rest with FastCGI?
两者混合运行可以吗?我在专用服务器上有 5 个站点。如果我用 mod_php 运行很少并用 FastCGI 休息可以吗?
I guess, but it will both be a nightmare to maintain and will probably be harder to configure for saving memory. Quite the contrary I believe.
我想,但这既是维护的噩梦,也可能更难配置以节省内存。我相信恰恰相反。
I am sure that my server goes down mostly because of improper memory usage by mod_php. I checked all scripts. Is there any way to make sure memory consumption on server remains nearly constant?
我确信我的服务器宕机主要是因为 mod_php 的内存使用不当。我检查了所有脚本。有什么方法可以确保服务器上的内存消耗几乎保持不变?
Configure memory and processes as I outlined above, and keep monitoring.
如上所述配置内存和进程,并保持监控。
Does complexity of .htaccess affects memory usage significantly? If yes, can it be a single reason to make server run out of memory?
.htaccess 的复杂性是否显着影响内存使用?如果是,是否是导致服务器内存不足的一个原因?
I don't think so. per-directory .htaccess can slow things down, but unless there is some serious bug in Apache, it should not cause mass memory consumption.
我不这么认为。每个目录的 .htaccess 可能会减慢速度,但除非 Apache 中存在一些严重的错误,否则它不会导致大量内存消耗。
Does apache MPM prefork/worker settings affect memory consumption? Do they affect mod_php and FastCGI mode equally?
apache MPM prefork/worker 设置会影响内存消耗吗?它们对 mod_php 和 FastCGI 模式的影响是否相同?
It might, but I recommend to stay away from worker, as PHP is mostly not thread safe.
可能,但我建议远离 worker,因为 PHP 大多不是线程安全的。
When I run "top" command, I see apache (httpd) consuming memory around 40MB. There are many instances of httpd running. Also in addition to that FastCGI forks some processes of similar size. What is normal memory size for httpd process?
当我运行“top”命令时,我看到 apache (httpd) 消耗了大约 40MB 的内存。有很多 httpd 正在运行的实例。此外,FastCGI 还派生了一些类似大小的进程。httpd 进程的正常内存大小是多少?
30MB is the min. The upper limit depends on your application (I have seen cases where it was ~1GB)
30MB 是最小值。上限取决于您的应用程序(我见过大约 1GB 的情况)
As I am running Wordpress on all of our sites, which will be good way in that context?
当我在我们所有的网站上运行 Wordpress 时,在这种情况下哪种方式比较好?
It is probably a matter of taste. I have recently moved away from apache towards nginx+fastcgi. it takes a bit of time to get used to, but it does work well. No problems whatsoever with wordpress (even not with supercache, which is rather involved in terms of web server).
这可能是一个品味问题。我最近从 apache 转向了 nginx+fastcgi。需要一点时间来适应,但效果很好。wordpress 没有任何问题(即使不是超级缓存,它涉及到 Web 服务器)。
Does FastCGI/SuExec works fine with APC? Do I need to reconfigure APC to work with SuEXEC and FastCGI.
FastCGI/SuExec 在 APC 上工作正常吗?我是否需要重新配置 APC 以使用 SuEXEC 和 FastCGI。
I am not using suExec, but fastcgi works well with APC. No need to configure anything.
我没有使用 suExec,但是 fastcgi 可以很好地与 APC 配合使用。无需配置任何东西。
回答by doublejosh
Tried switching to mod_php, many claims about it's speed. Didn't realize mod_phpburns through extra memory when serving static files.(I didn't care much about the security issue with the root owning files).
尝试切换到mod_php,很多人声称它的速度。没有意识到mod_php在提供静态文件时会消耗额外的内存。(我不太关心 root 拥有文件的安全问题)。
Without a CDN setup, fastcgiis your choice for serving PHP apps. Without it, switching from fcgito mod_phpslowed my page generation time way down, from 3895ms to 6264ms (admin pages on shared hosting).
如果没有 CDN 设置,fastcgi是您提供 PHP 应用程序的选择。没有它,从fcgi切换到mod_php 会减慢我的页面生成时间,从 3895 毫秒到 6264 毫秒(共享主机上的管理页面)。

