Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FastCGI applications from within a C# app

Tags:

c#

php

fastcgi

I'm developing a small webserver in C# as part of a larger project (the nature of the project prevents me from using something like apache nginx, which would be my first choice).

The webserver needs PHP to process some of the requests it recieves.

At the moment I'm running php as a cgi using System.Diagnostics.Process and piping data to and from. This works but is pretty slow (presumably from the overhead from PHP start starting from scratch, is the main issue). So I want to try using FastCGI instead.

I've looked at the FastCGI spec, and made a start at implementing a basic subset, but haven't have much luck. Most of of the examples I've seen have been libraries for developing FastCGI modules, not for invoking them, so I've had very little to use as reference.

Has any one got any experience of doing this under .NET, or could recommend any useful resources for this kind of project?

like image 711
Twelve47 Avatar asked Jan 21 '11 15:01

Twelve47


People also ask

What is the difference between CGI and FastCGI?

What makes a difference from CGI is that with FastCGI the running process of the application lasts longer and it is not immediately terminated. After the application finishes processing and returns the output data, the process is not terminated and is being used for processing further requests.

What is a FastCGI application?

FastCGI is a programming interface that can speed up Web applications that use the most popular way to have the Web server call an application, the common gateway interface (CGI).

Is FastCGI fast?

FastCGI is a fast, open, and secure Web server interface that solves the performance problems inherent in CGI, without introducing the overhead and complexity of proprietary APIs (Application Programming Interfaces).


1 Answers

I also had to do something similar (during a transition period) and used MiniHttpd: an HTTP web server library. What I had to do was slightly different as I didn't need an httpd rather a way of executing PHP from a C# application.

It basically references the unmanaged code straight out of the DLL using the file on disk (see PhpAppDirectory.cs).

like image 126
Richard Harrison Avatar answered Nov 09 '22 01:11

Richard Harrison