Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a webserver interface with PHP

Tags:

php

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.
like image 390
Somebody Avatar asked Aug 14 '11 12:08

Somebody


1 Answers

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

like image 71
mario Avatar answered Sep 29 '22 16:09

mario