I'm developing a web server in Csharp and I want to install php compiler on it.
Current state: the web server is working and receiving connection, can compile PHP pages, I'm invoking PHP compiler using procces start
and I can send GET parameters as arg like that:
php.exe name=1 /index.php
The problem is how to send post, get data and HTTP headers to the compiler in such better way?
There is indeed a rather hackish solution to pass HTTP headers on the command-line interface: The -B
or --process-begin
flag allows for code to be run before the script in question. This could be used to inject data into the $_SERVER
superglobal array to simulate headers being set. E.g. for X-Foo: bar
to be set, you would run this:
php.exe --process-begin '$_SERVER["HTTP_X_FOO"] = bar;' /index.php
The same can be done with the $_GET
and $_POST
superglobals. However, this really is just a hack and I cannot recommend this outside of academic environments for security reasons.
A slightly better way were to take advantage of the builtin webserver. If you have coded cleanly enough, it should be no problem to reroute incoming requests to PHP and channel the result back. This will only work flawlessly if you do not require any virtualhosts, though. And as with the solution above, this has no place outside of research!
The absolute correct way were to implement the Common Gateway Interface. PHP comes with a CGI interface itself, so speaking CGI to it is trivial. If you run into scalability problems, you may want to switch to FastCGI. A sample implementation can be found here.
One last thing: PHP is an interpreted language, not a compiled one.