I am currently writing my own server in C++ for Posix systems. Before anyone says anything about how I should really use a prebuilt server, please be aware that I do use prebuilt servers for anything business related. This project is entirely a learning experience.
I would like this system to support server side scripting as well as static hosting. I run into a problem when I try to include support for the most important server side scripting language: PHP.
Standard PHP provides several predefined variables that give access to information about an incoming request. It also provides standard HTTP functions that interact with the request in specific ways. Further, it is supposed to be possible to perform IO operations on the request and response bodies by using the filenames php://input
and php://output
respectively to refer to the appropriate socket and permissions.
I know that I would be able to define all these variables and implement all these functions myself in the top of a wrapper script and then use include
to run the user's script in the same context, but that seems cumbersome. I also have no idea how to map php://input
or php://output
to the actual request socket's file descriptor.
I don't know much about PHP interpreters. Is there a way to provide essential request data (user-agent, INET address, method, URI, version, headers, socket file descriptor, and maybe something I'm forgetting) to the PHP interpreter to be able to access the native definitions and implementations of these variables and functions? Or is it standard practice for the author of the server to define and implement these himself?
Most important, if I do have to implement these things myself, how do I map php://input
and php://output
to the correct file descriptor and permissions?
Thanks to everyone. Any help is appreciated.