Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does PHP interact with HTTP servers? (like lighttpd) [duplicate]

Tags:

php

lighttpd

Possible Duplicate:
I never really understood: what is CGI?

In the lighttpd config, we define two paths (as shown below), one of them is the binary of PHP, the other is the socket path. My question is, in which point does the lighttpd fetches the final HTML output created by PHP? Does the binary give an output to lighttpd as a response? Or does it create a temporary file in another place and server fetches it?

fastcgi.server = ( ".php" => ((
                     "bin-path" => "/usr/bin/php-cgi",
                     "socket" => "/tmp/php.socket"
                 )))
like image 857
tolga Avatar asked Dec 27 '12 22:12

tolga


2 Answers

PHP can run as a CGI binary, or as an Apache module. When being used as a CGI binary, the HTTP server will communicate with PHP via pipes or named pipes. These can utilize stdout which is a form of interprocess communication which does not require any disk access. If run as an Apache module, PHP is effectively part of the Apache server. This is significantly faster than being executed as a CGI, but has some security limitations.

like image 81
Jordan Mack Avatar answered Nov 03 '22 00:11

Jordan Mack


From my understanding, the bin-path is used to fire up the FastCGI server (if it's not started yet) whereas the socket is used to proxy the request into the server once started.

The final HTML is therefore pulled from /tmp/php.socket after the request has been processed; it's a named pipe as opposed to a network socket but they're quite similar in any other respect.

like image 24
Ja͢ck Avatar answered Nov 02 '22 23:11

Ja͢ck