简体   繁体   English

Apache的mod_php还是FastCGI? 哪个对Wordpress有好处?

[英]Apache's mod_php OR FastCGI? Which is good for Wordpress?

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. 在我的发现和测试中,我发现FastCGI略胜一筹。 I like FastCGI's support for SuEXEC most. 我最喜欢FastCGI对SuEXEC的支持。 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... 那么它的好指标,但我对不同的因素感兴趣,这是我的问题......

  1. Which method of running PHP consumes less memory? 运行PHP的哪种方法占用的内存较少?
  2. 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之间波动。
  3. But with FastCGI, first response from server comes very late. 但是使用FastCGI,来自服务器的第一个响应来得非常晚。 I see with FastCGI there is an initial delay per webpage request. 我看到FastCGI每个网页请求有一个初始延迟。 Once first response from server arrives, other items like images, css, js loads pretty faster. 一旦服务器的第一个响应到达,其他项目,如图像,css,js加载速度相当快。
  4. Is it OK to run mix of both? 两种混合运行都可以吗? I have 5 sites on dedicated server. 我在专用服务器上有5个站点。 Is it ok if I run few with mod_php and rest with FastCGI? 如果我使用mod_php少量运行并使用FastCGI休​​息,这样可以吗?
  5. I am sure that my server goes down mostly because of improper memory usage by mod_php. 我确信我的服务器出现故障主要是因为mod_php的内存使用不当。 I checked all scripts. 我检查了所有脚本。 Is there any way to make sure memory consumption on server remains nearly constant? 有没有办法确保服务器上的内存消耗几乎保持不变?
  6. Does complexity of .htaccess affects memory usage significantly? .htaccess的复杂性是否会显着影响内存使用? If yes, can it be a single reason to make server run out of memory? 如果是,是否可以使服务器内存不足?
  7. Does apache MPM prefork/worker settings affect memory consumption? apache MPM prefork / worker设置会影响内存消耗吗? Do they affect mod_php and FastCGI mode equally? 它们是否同样影响mod_php和FastCGI模式?
  8. When I run "top" command, I see apache (httpd) consuming memory around 40MB. 当我运行“top”命令时,我看到apache(httpd)消耗大约40MB的内存。 There are many instances of httpd running. 有许多httpd运行的实例。 Also in addition to that FastCGI forks some processes of similar size. 此外,FastCGI还会分配一些类似大小的进程。 What is normal memory size for httpd process? httpd进程的正常内存大小是多少?
  9. As I am running Wordpress on all of our sites, which will be good way in that context? 当我在我们所有的网站上运行Wordpress时,在这种情况下这将是一个好方法吗?
  10. Does FastCGI/SuExec works fine with APC? FastCGI / SuExec与APC一起工作正常吗? Do I need to reconfigure APC to work with SuEXEC and FastCGI. 我是否需要重新配置APC才能与SuEXEC和FastCGI配合使用。

Please note, I am less interested in surviving against DIGG or traffic spikes. 请注意,我对DIGG或交通高峰的生存兴趣不大。 I want a way which can make server stable and predictable. 我想要一种可以使服务器稳定和可预测的方法。

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. 我有512MB物理内存,400MB交换和我的服务器疯狂的内存不足。 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. 平均内存需求大约为350MB,只是内存使用量激增使得内存几秒钟无法访问,如果在那几秒钟窗口中收到的额外点击次数很少,那么当mysql和其他所有fellas运行正常时,apache崩溃了。

Please help me out guys. 请帮帮我们。 I am not gonna buy more RAM or hardware. 我不会买更多的RAM或硬件。 I am damn sure that problem is in my configuration. 我很确定问题出在我的配置中。 Sorry if I sound arrogant or ignorant. 对不起,如果我听起来傲慢或无知。

Which method of running PHP consumes less memory? 运行PHP的哪种方法占用的内存较少?

I assume that per PHP-processed request they are more or less the same. 我假设根据PHP处理的请求它们或多或少相同。 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. 但是,如果你也将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. 如果您仔细设置MaxClients,MinSpareServers和MaxSpareServers,您几乎可以知道正在运行的进程数。 If you also set memory_limit within your PHP config, you can calculate how much memory you need. 如果您还在PHP配置中设置memory_limit,则可以计算所需的内存量。 You can do the same for fcgi too, since you can decide how many processes are running. 你也可以为fcgi做同样的事情,因为你可以决定运行多少进程。

But with FastCGI, first response from server comes very late. 但是使用FastCGI,来自服务器的第一个响应来得非常晚。 I see with FastCGI there is an initial delay per webpage request. 我看到FastCGI每个网页请求有一个初始延迟。 Once first response from server arrives, other items like images, css, js loads pretty faster. 一旦服务器的第一个响应到达,其他项目,如图像,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. 我在专用服务器上有5个站点。 Is it ok if I run few with mod_php and rest with FastCGI? 如果我使用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. 我确信我的服务器出现故障主要是因为mod_php的内存使用不当。 I checked all scripts. 我检查了所有脚本。 Is there any way to make sure memory consumption on server remains nearly constant? 有没有办法确保服务器上的内存消耗几乎保持不变?

Configure memory and processes as I outlined above, and keep monitoring. 如上所述配置内存和进程,并继续监视。

Does complexity of .htaccess affects memory usage significantly? .htaccess的复杂性是否会显着影响内存使用? If yes, can it be a single reason to make server run out of memory? 如果是,是否可以使服务器内存不足?

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? apache MPM prefork / worker设置会影响内存消耗吗? Do they affect mod_php and FastCGI mode equally? 它们是否同样影响mod_php和FastCGI模式?

It might, but I recommend to stay away from worker, as PHP is mostly not thread safe. 它可能,但我建议远离工作者,因为PHP主要不是线程安全的。

When I run "top" command, I see apache (httpd) consuming memory around 40MB. 当我运行“top”命令时,我看到apache(httpd)消耗大约40MB的内存。 There are many instances of httpd running. 有许多httpd运行的实例。 Also in addition to that FastCGI forks some processes of similar size. 此外,FastCGI还会分配一些类似大小的进程。 What is normal memory size for httpd process? httpd进程的正常内存大小是多少?

30MB is the min. 最小30MB。 The upper limit depends on your application (I have seen cases where it was ~1GB) 上限取决于您的应用程序(我见过大约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. 我最近从apache转向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). 使用wordpress没有任何问题(即使没有超级缓存,这与Web服务器相关)。

Does FastCGI/SuExec works fine with APC? FastCGI / SuExec与APC一起工作正常吗? Do I need to reconfigure APC to work with SuEXEC and FastCGI. 我是否需要重新配置APC才能与SuEXEC和FastCGI配合使用。

I am not using suExec, but fastcgi works well with APC. 我没有使用suExec,但fastcgi适用于APC。 No need to configure anything. 无需配置任何东西。

Tried switching to mod_php , many claims about it's speed. 尝试切换到mod_php ,许多人声称它的速度。 Didn't realize mod_php burns through extra memory when serving static files. 没有意识到mod_php在提供静态文件时会通过额外的内存来消耗 (I didn't care much about the security issue with the root owning files). (我不太关心root拥有文件的安全问题)。

Without a CDN setup, fastcgi is your choice for serving PHP apps. 没有CDN设置, fastcgi是您提供PHP应用程序的选择。 Without it, switching from fcgi to mod_php slowed my page generation time way down, from 3895ms to 6264ms (admin pages on shared hosting). 没有它,从fcgi切换到mod_php会减慢我的页面生成时间, 从3895ms减少到6264ms(共享主机上的管理页面)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM