How does PHP interface with Apache?

后端 未结 4 756
梦如初夏
梦如初夏 2020-12-13 07:23

I\'ve almost finished writing a HTTP/1.0 compliant web server under Java (no commercial usage as such, this is just for fun) and basically I want to include PHP support. I r

相关标签:
4条回答
  • 2020-12-13 07:35

    There are 3 ways PHP can be invoked from Apache:

    1) as a module - this involves linking the php interpreter against a library of hooks published by the webserver

    2) CGI - the webserver starts up an instance of the interpreter for each request and passes parameters to the interpreter via stdin, the command line and environment variables, stdout is sent to the client and stderr should be written to the error_log

    3) fastCGI - this eliminates the overhead of starting a new process for each request - the interpreter runs as a daemon

    CGI is the simplest to implement but does not scale/perform well, the module would be the hardest by far. FastCGI is nearly as fast as the module approach. CGI and fastCGI are open, well documented APIs.

    There are other ways of achieving your goal - e.g. Quercus

    C.

    0 讨论(0)
  • 2020-12-13 07:37

    To put it simply, this is how it works:

    Apache normally serves files by fetching the file and sending the stream down the HTTP connection. With PHP, however, Apache fetches the file, pipes it into the PHP binary, and sends the output stream from the command down the HTTP connection.

    0 讨论(0)
  • 2020-12-13 07:40

    The key word is CGI.
    It is dramatically simple protocol, which serving web-servers for ages.
    It is not the only way for PHP to interact with a web-server, but most common and easy to implement one.

    In short, your server must set up some environment variables, and then call a cgi-script which is just a php script itself.

    0 讨论(0)
  • 2020-12-13 07:47

    In addition to the php file, HTTP request, and the client host name, there are certain other items of information typically passed to PHP to set certain other elements of the $_SERVER superglobal. The linked documentation page has a list of what is typically set.

    0 讨论(0)
提交回复
热议问题