3

I see most answers believe mod_php is less efficient because memory footprint will be higher due to serving static files,like this one.

But I have a different opinion as follows:

As a matter of fact,code section are shared among fork()ed processes,so the memory footprint predicate shouldn't hold.

The only reason I can think of is that mod_php is non-threadsafe so that web server can only create subprocesses for each request.

While in fastcgi mode web server can boost up the performance by multiplexing tricks,thus reducing the fork() overhead.

In a word,the drawback of mod_php is not its memory foot print,but the overhead of fork(),but if mod_php can be thread_safe,fork() won't be necessary and this will be the most efficient solution to serve requests.

The above is my opinion,but not 100% sure.

Is that right?

Community
  • 1
  • 1
Je Rog
  • 5,675
  • 8
  • 39
  • 47

1 Answers1

3

Forking is quite fast and default apache + mod_php installations also fork. (unless worker mpm is used).

The real reason is (kind of) as follows:

Standard mod_php will have reasonably big process, because the process contains contain both php and all the other apache modules, etc. If php is in a separate process, the php process can have a shorter lifetime, and quickly pass the result back to apache when PHP is done.

The other reason (as you've mentioned) is that PHP is not touched for non-php requests.

The fact that you can switch to worker mpm when using FastCGI is just bonus; but does add to the efficiency.

In general with these types of designs you'd want to always try to make both the apache and php processes as short-living as possible, and splitting them up helps.

But yea.. forks are very fast, and in certain designs they can actually operate better than Threads on Linux (no source, I just remember reading this). For webserver-type systems, I do believe Reactor-pattern based systems work even better. NGinx and Varnish are prime examples of this.

Evert
  • 93,428
  • 18
  • 118
  • 189
  • 4
    I think apache and PHP are in the same process by mod_php,not separate process. – Je Rog Jun 13 '11 at 14:00
  • Sorry, that's more of a bad wording problem.. Fixing that paragraph. – Evert Jun 13 '11 at 14:12
  • but I still don't think that's the reason,as in both mod_php and fastcgi mode,php and apache modules are always in memory,the only difference is juat that they are in different processes.That is,in fastcgi mode php worker processes are also persistent,not shorter lifetime. Again,memory footprint is not the problem. – Je Rog Jun 13 '11 at 14:20
  • 1
    Well the benefit lies in the time spent. Even though the memory footprint *per request* is similar (even a bit more) a lot less memory is needed for the entire request, and the request goes out quicker. Also less FastCGI workers are needed per apache worker, reducing the footprint too. Your question may just be too vague.. what are you trying to figure out? – Evert Jun 13 '11 at 22:51