Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between mod_php and cgi php script?

Tags:

php

webserver

cgi

What are the differences between mod_php and cgi php script?

I mean, why it's better (is it?) to use mod_php instead simple php scripts, running them as CGIs?

Thanks

like image 433
Simone Margaritelli Avatar asked May 02 '10 16:05

Simone Margaritelli


1 Answers

When using CGI : a PHP process is launched by Apache, and it is that PHP process that interprets PHP code -- not Apache itself.

In theory, a distinct PHP process has to be created for each request -- which makes things slower : Apache has more work to do to answer a request.
(Well, as pointed out by @AlReece45 in a comment, this can be made better using FastCGI)


When using PHP as an Apache module (mod_php, or mod_php5), the PHP interpreter is kind of "embedded" inside the Apache process : there is no external PHP process.

Which means :

  • No forking to answer a request (faster)
  • Better communication between Apache and PHP


Generally speaking, I would say that mod_php is the solution that's used the most.

like image 54
Pascal MARTIN Avatar answered Oct 27 '22 06:10

Pascal MARTIN