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

2

6

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"
                 )))
Gynous answered 27/12, 2012 at 22:38 Comment(3)
Pipes usually (see CGI). But since this config specifies a socket, you're presumably using the FastCGI binary.Arbil
Not a duplicate; the config snippet is about FastCGI, not CGI. bin-path means lighty will spawn the backend (opposed to spawning externally), the socket is the path to a "unix socket" (not a named pipe, a real socket). lighty will connect to this socket for each request, the same way a browser will connect to the webserver - but it uses a different protocol for the details.Monetary
Would you please remove the "duplicate" statement, because this question is not a duplicate.Gynous
M
1

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.

Magenmagena answered 28/12, 2012 at 1:22 Comment(0)
J
1

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.

Judson answered 27/12, 2012 at 22:42 Comment(0)
M
1

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.

Magenmagena answered 28/12, 2012 at 1:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.