Main menu

PHP execution mode for Apache, Which one is best

There are many ways to execute PHP scripts in a web server often called modes. There are three most common PHP handlers in Apache..

  1. CGI
  2. Apache Module
  3. Fast CGI

1. CGI : CGI is an old way to execute scripts from web servers. This way apache used external process for executing the scripts. Apache send the scripts to interpriter, get the result from it and send back to client. By using CGI an external process is required so it’s become slow but process footprint become small size. Using an external process for execution it provide a better level of security.

Pros

  • Better security as PHP code is isolated from Web server.
  • Small footprint of processes.
  • Process not used PHP interpreter for static components.

Cons

  • Poor performance.

2.  Apache Module (mod_php) : When using Apache module or mod_php the PHP interpreter is embedded in each Apache process when it’s spawn. This way Apache can execute PHP scripts faster and removing the dependance of external process. It’s good if are using many PHP applications on our Web server for faster processing. Only disadvantages is that loading PHP interpreter in each request makes process Harvey or consume more memory also Apache process loads the PHP interpreter for non PHP files like html and images.
Pros

  • No external process means faster execution of PHP scripts
  • PHP setting can be manages by Apache from .htaccess directives.

Cons

  • Load PHP interpreter makes process footprint larger and used more memory.
  • Load PHP interpreter for non PHP files.
  • Files created from Apache is owned by Apache itself.

3. Fast CGI :Fast CGI is an middle workaround of both methods CGI and mod_php. Fast CGI use a Socket between PHP interpreter and Apache web server. So all the request from Apache forwarded to interpreter with better scalability.

Pros

  • Better security then mod_php.
  • Small process footprint.
  • Better performance.

Cons

  • Can not use .htaccess directives for managing PHP configuration.
FacebookTwitterGoogle+RSS