1

I have written a web server in C and I want to add some scripting language support like (PHP,...) to the server.

How can I interact with PHP and other scripting language?

How send them requests and get responses?

Is there any document or guide about web server developing or web server architecture?

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
m.ch
  • 15
  • 4

1 Answers1

1

The first thing that comes to mind is to use CGI or FastCGI (see http://en.wikipedia.org/wiki/FastCGI). That's how nginx (a popular web server also written in C) supports PHP, for example.

It's much faster to add support for FastCGI and then rely on software like PHP-FPM (PHP FastCGI implementation) rather than to write your own PHP module. However, you will have to run an extra background process, listening to its own UNIX socket or TCP port.

Another possibility is to execute CLI handler for corresponding language (eg. CLI PHP) upon HTTP request, but I suspect that performance will be much lower.

For example, user requests /something.php?query=parameter from your web server. Your web server looks for something.php file in specified folder (your web servers config file), then executes (interprets) it using PHP CLI, waits for response and passes that response back to web user.

Denis Mysenko
  • 6,366
  • 1
  • 24
  • 33