[FASTCGI] The right way to debug a FastCGI app
rclemley at yahoo.com
Wed Jul 14 01:01:46 EDT 2010
On 07/12/2010 02:41 PM, Wes Widner wrote:
> I've recently written an application using the FastCGI framework (in
> C) and I've been very impressed with the speed it offers. However when
> I went to write an extension to my application I've run into some
> difficulties debugging my code so I wanted to see if anyone here had a
> better idea of how to go about debugging a FastCGI application.
> Here is what I am attempting to do thus far:
> Run cgi-fcgi through gdb: gdb cgi-fcgi
> Then run my fastcgi application directly: (gdb) r -start -connect
> 127.0.0.1:9005 <http://127.0.0.1:9005> ./myapp.fcgi 1
> This produces the output:
> Starting program: /usr/bin/cgi-fcgi -start -connect 127.0.0.1:9005
> <http://127.0.0.1:9005> .//myapp/.fcgi 1
> [Thread debugging using libthread_db enabled]
> Program exited normally.
The cgi-fcgi program exits after each request is processed. This is why
you keep seeing "Program exited normally". Plus your app is not doing
anything because you're not sending any CGI info to cgi-fcgi.
If you want to debug your FastCGI app, you need to start your FastCGI
app with the debugger, or attach gdb to your FastCGI app process.
It seems your using a gnuish/unixish system, so why don't you configure
your web server to send FastCGI requests directly to your app? With
Apache 2, all you need is the fastcgi module (libapache2-mod-fastcgi on
Debian). If you get a lot of hits, you'll incur quite a bit of overhead
starting cgi-fcgi processes for each request. I've never used cgi-fcgi
and I never plan to use it. I can see no reason why you would want to
use cgi-fcgi, especially if your concerned with performance. There's no
advantage to using cgi-fcgi for debugging.
Do this (if using apache 2):
1. configure and test apache2 with your FastCGI app as a
"FastCgiServer" (aka internal fastcgi server).
2. restart apache 2
4. attach gdb to your FastCGI app (hint: use the ps command to get the
3. set a break point on FCGI_accept() and continue your FastCGI process.
4. send a request from your web browser to your web server
5. see the breakpoint hit in your debugger
In any case: Your FastCGI app should never exit. The same FastCGI
process loops continually, receiving and processing FastCGI requests.
More information about the FastCGI-developers