开发者

How does a webserver interface with PHP

I want to handle http requests via another webserver or own writt开发者_开发百科en server in future.

I want to understand how to provide php with request data properly.

  • in what form request data should be provided
  • how data is provided to php, via stdin or somehow else
  • how php handles received request data afterwards, any additional actions required to fill $_SERVER variables etc.


It's pretty simple actually. The Webserver communicates with PHP through the CGI interface. This entails setting up environment variables, invoking the php interpreter, piping a POST body through stdin, and then reading the PHP response from stdout.

  • Call PHP from virtual/custom "web server"
  • How to pass POST data to the PHP-CGI?
  • http://pear.php.net/package/HTTP_Server
  • What is Common Gateway Interface (CGI)?

As to PHP postprocessing the $_SERVER variables: That's fairly minimal, it only constructs PHP_SELF and PHP_AUTH_USER etc. as documented in the manual. The rest is provided by the webserver (e.g. all HTTP headers converted into HTTP_* env variables).


Go download the source code for php, and look at the code for mod_php, written in C I believe, cause that's where it's done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜