Recent

Author Topic: FastCGI vs. CGI  (Read 553 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1826
FastCGI vs. CGI
« on: July 16, 2026, 12:45:05 pm »
I'm comparing two approaches, CGI and FCGI. Both program share the same webmodules and datamodule. The internal processes are the same.

Only one thing: when the client try to download a rather large dataset (it is downloaded as TStream), CGI works fine, but FCGI issues 500 error. I extended action timeout, etc. of IIS FastCGI setup, but none had effect. (Windows Server 2019)

Currently FCGI only processes one request.

I asked AI, but no satisfactory answer. What could be possible reason?

korba812

  • Hero Member
  • *****
  • Posts: 501
Re: FastCGI vs. CGI
« Reply #1 on: July 17, 2026, 12:48:06 pm »
FastCGI works slightly differently than CGI – once launched, it can handle multiple requests. A CGI application terminates after handling a request. It's possible that your FastCGI application, on subsequent requests, attempts to access a resource that was freed when handling the first request.
Also check the server logs.

Thaddy

  • Hero Member
  • *****
  • Posts: 19625
  • Glad to be alive.
Re: FastCGI vs. CGI
« Reply #2 on: July 18, 2026, 10:56:40 am »
It is not slightly different it is completely different:
fcgi is a single process, capable of handling multiple requests at the same time.
cgi will start a new process per request.
What you observe is that the cgi process is capable of handling lengthy loads. fcgi can do that too, but needs a bit extra code for session protection for lengthy things, because it is a single process and a client may simply time out.
It depends a bit on application what you should use, using cgi may exhaust the server's resources when many requests are expected. But with low traffic cgi is a very good and stable solution.
If your server is Apache, consider using an Apache module as alternative and let Apache handle traffic issues.
You can write Apache modules with FPC too. It is in the standard Freepascal distribution.
« Last Edit: July 18, 2026, 11:22:36 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

korba812

  • Hero Member
  • *****
  • Posts: 501
Re: FastCGI vs. CGI
« Reply #3 on: July 18, 2026, 12:36:43 pm »
fcgi is a single process, capable of handling multiple requests at the same time.
The fcgi handles only one request at a time, similar to cgi. The difference is that it doesn't terminate after handling a request, it simply waits for the next one.

Thaddy

  • Hero Member
  • *****
  • Posts: 19625
  • Glad to be alive.
Re: FastCGI vs. CGI
« Reply #4 on: July 18, 2026, 01:32:45 pm »
Yes, semi-sequential, but the main - real, important, difference is it is a single process and cgi spawns a process per reguest. Hence fcgi unlikely runs out of server resources, but cgi can exhaust the server pretty fast. cgi is better suited for low connection loads. modules are even better, because you would use the Apache scheduling.
Any "programmer" that knows only one programming language is not a programmer

egsuh

  • Hero Member
  • *****
  • Posts: 1826
Re: FastCGI vs. CGI
« Reply #5 on: July 20, 2026, 06:33:08 am »
I'm running on Windows Server.
It seems not the problem of fastcgi program, but of IIS. On nginx, it runs without problem with rather long (1-2 minutes) process.
I configured Windows Server so that nginx processes a specific fcgi process leaving other requests to IIS, with the help of AI.
CGI is stable and good. But my server is for survey. Generally low traffic, but high concentration, e.g. when text message containing the URL is delivered to tens of thousands of respondents at the same time. Still not all of them respond at the same time, but the CPU usage went up to 70% (with CGI).
Anyway now I can use any of CGI / FCGI (internal programs are the same) by simply changing URL. Need to test more on high concentration of requests.

 

TinyPortal © 2005-2018