3

We've been thinking on writing a php interpreter for a project we've been working on. Interpreting aside, I've been trying - with no success - to find how the PHP interpreter interfaces with the http server. So I've come to you, o' dear knowledgeable people of Stack Overflow.

I have read that php listens on localhost:9000. Goes without saying that I tried to connect to that and it was no use. Maybe the webserver runs "php file.php" and gets the output?

Also, could a php interpreter that interprets .php files and our interpreter (lets call it pqp for the sake of argument) that interprets .pqp files coexist in a single webserver?

Thank you very much!

Lartu
  • 188
  • 1
  • 13

1 Answers1

3

There are certain ways in which PHP interacts with a webserver. One is indeed to pipe PHP files into the PHP cli and serve the output as in this question. As I wrote there: It's really not recommended.

The next best thing is to expand the sapi of PHP, which is providing a set of connectors to a webserver. In this case, PHP is going to act like a webserver module (see apache+mod_php). A downside of this is that PHP is trying to parse everything it gets its hands on.

A webserver-independent method is to connect to PHP via the Common Gateway Interface, whcih is a well-defined interface for various interactive serverside components. It is, however, terribly slow (and a bit insecure).

The final step is to implement FastCGI. This is an improvement over CGI in that it tries to connect to a running process. In the PHP world, this is achieved through php-fpm which (by default) indeed listens on 9000/tcp.

Community
  • 1
  • 1
DaSourcerer
  • 6,288
  • 5
  • 32
  • 55