6

I want to handle http requests via another webserver or own written 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.
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Somebody
  • 9,316
  • 26
  • 94
  • 142
  • 1
    You asking how a POST or GET is formed? – Matt Aug 14 '11 at 12:08
  • Yes and how $_SERVER data is filled, and everything else required for generating html. Any books, tutorials, wiki, docs on this will do. :) – Somebody Aug 14 '11 at 12:10
  • @Seriousdev i want to learn deep mechanics of php and write own async web server for studying purposes. – Somebody Aug 14 '11 at 12:13
  • So, you want to build an HTTP server in PHP. Not that easy: http://www.w3.org/Protocols/rfc2616/rfc2616.html – seriousdev Aug 14 '11 at 12:16
  • Not in php. HTTP Server will be written on low level language. I just need php to do it work as before, but request handled by my http server. – Somebody Aug 14 '11 at 12:18
  • You may want to rephrase your question to something along the lines of "How does a webserver interface with PHP?" – deceze Aug 14 '11 at 12:19
  • This is a _highly_ complicated subject. Replicating the interface between httpd and php is no small task. Perhaps start by writing an Apache module to get at least half of the pipeline under your belt. – Lightness Races in Orbit Aug 14 '11 at 13:21

2 Answers2

6

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.

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).

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291
0

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.

DGM
  • 26,629
  • 7
  • 58
  • 79