5

I understand that there are four different PHP handlers out there (AFAIK).

  • CGI (php-cgi)
  • FastCGI (php-fpm)
  • Mod_PHP
  • suPHP

I need to know the pros and cons of these handler and what environments each are suited for?

For example if I'm running a shared hosting server which of the above handlers is right for me? Or if I'm managing a private server?

2hamed
  • 469
  • 1
  • 5
  • 23
  • Have you done any research? Google? Anything? Seriously, we'd love to help, but you need to put some effort in. Particularly if you're asking us "what's best" (a question we can't answer for you **because we don't know your environment**...) – voretaq7 Nov 13 '12 at 23:53
  • @voretaq7 Yes, I have done my research but I needed a concrete answer so I thought maybe some people would like to help and serverfault is where to seek it. I think you all are getting way above your heads. You could've simply asked me to put more details instead of closing down my question. Thanks for nothing. – 2hamed Nov 14 '12 at 08:51
  • If you feel your question was closed unfairly please [open a discussion on Meta](http://meta.serverfault.com/questions/ask) - I'm happy to reverse the closure if the community thinks I messed up. (Or you can take the criticism I offered, rework your question to be less subjective and *show us* the research effort you've put in, and get it reopened without having to grouse on Meta.) – voretaq7 Nov 14 '12 at 16:17

1 Answers1

6

Those are not really "6 PHP Types", rather two PHP types, each running in 3 different Apache implementations.

suphp, suphp_worker and suphp_event

suPHP itself is a wrapper for PHP, running PHP under given user rights (eg differing from the rights Apache runs under) plus an Apache module (mod_suphp) which allows you to run suPHP - basically in a CGI mode. CGI mode simplified means, that each request passed through to PHP starts a new PHP (runtime) process. This is expensive, in terms of CPU usage, and slower compared to a persistent PHP runtime (~about 3-5 times, i'd guess).

I assume this first variant uses the Apache's prefork MPM, which is widely used and tested but rather slow, compared to other MPMs. Prefork does what it name implies: It forks a given amount of apache processes and holds them available for incoming requests.

The next (suphp_worker) uses the worker MPM instead. Worker is a mix of pre-spawned processes and threads, which is generally faster than prefork (for delivering static contents about twice) and uses less memory.

The last (suphp_event) seems to use suPHP + MPM event, which uses yet again another process/thread model than worker. From benchmarks i've seen, event and worker are about the same speed - the event MPM (at least using Apache 2.2, which your provider probably does) is marked as experimental.

mod_php, mod_php_ruid2 and mod_php_itk

This is a differnt kind of PHP handler implementation: Apache pre-starts a PHP runtime and passes incoming requests to it, spawning new processes as needed. This is considerable faster than suPHP but comes with the downside of having no user right separation: all the php processes run under the same rights as Apache itself.

The first variant probably uses the prefork MPM (described above) as mod_php is incompatible with the thread models from worker or event.

The second variant (mod_php_ruid2) seems to use the Apache module mod_ruid2 in addition, which allows you to run each Apache VirtualHost under differnt user rights - this includes PHP processes. It has a long list of incompabilities which you should consider.

The last variant (mod_php_itk) uses the third party ITK MPM for Apache, a fork of the Apache prefork MPM with the option run each VirtualHost under given user rights. It also gives you the ability to enforce additional limits (eg amount of clients) per VirtualHost.

Suggestion

If those are your only choice, and you are "alone" on your Machine (aka: you do not plan shared hosting) i would probably stick with good ol' mod_php.

If you are planing multiple websites you need to check with your priorities:

  • security over performance: go with suphp_worker. Both (worker MPM and suPHP) are widely tested and give you a good starting point for security. Performance for static files should be good, PHP not so much.
  • performance over security: Probably mod_php_ruid2, but only because i have bad experience with ITK

I do prefer using a third option, which uses FastCGI, giving you even more possibilities to separate rights and access priviliges - but this seems not to be offered.

Chris S
  • 77,337
  • 11
  • 120
  • 212
ukautz
  • 414
  • 2
  • 2
  • Thank you for your comprehensive answer. I mainly serve my own websites on this VPS. About FastCGI, there is checkbox while adding clients which says Enable FastCGI. Does that mean I have it installed? – 2hamed Nov 13 '12 at 09:39
  • A big answer - unfortunately the stuff about mod_php is wrong - it doesn't start additional processes - the PHP interpreter runs in the same process/thread as apache. – symcbean Nov 13 '12 at 12:29