4

I am writing a Java web server and right now I am able to service .HTML files fine, but I am having a hard time figuring out how to handle .PHP files which require $_POST and $_GET.

How do web servers usually fill these arrays? There is no way to fill them using the command-line from what I can tell since I was originally thinking to pipe the stdout of an exec("php whatever.php some $_get args), but that's not possible without physically changing the php code to exploding the args and filling them into $_GET which I don't want to do -- I want to do it the way web servers do it.

Does anyone have suggestions of how web servers do things like this?

CompEng88
  • 1,336
  • 14
  • 25
  • This might help: http://www.php.net/manual/en/java.servlet.php – Douglas Aug 28 '11 at 02:23
  • 1
    Also you cannot use the normal `php` interpreter. You need the **`php-cgi`** variant: http://stackoverflow.com/questions/7047426/call-php-from-virtual-custom-web-server/7047581#7047581 – mario Aug 28 '11 at 02:42

1 Answers1

5

You can use interface with PHP via Common Gateway Interface (CGI), which boils down to setting up a bunch of environment variables and then invoking PHP.

REQUEST_METHOD="GET"
QUERY_STRING="param1=value1&param2=value2"

The CGI protocol is defined in RFC 3875.

Community
  • 1
  • 1
John Kugelman
  • 349,597
  • 67
  • 533
  • 578