Re: How to handle "Internal Server Error"

jancha <[email protected]>
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <[email protected]>
Hi.

On Thursday 28 July 2005 00:43, Jack wrote:
> Hello Jancha,
>
> Thanks a lot for the reply. It is very helpful. Two more questions:
>
> Re: 2) I found the 600 seconds definition in mod_fastcgi source files.
> I think I'll change that and rebuild mod_fastcgi. I plan to make it 0 or 1.
> Is there any reason I shouldn't make it so short?

This can be done, however, might be a bad idea because:
if your program is faulty, fastcgi will keep re-launching it all the time - 
and what if the reason for crashing is for instance some kind of memory leak? 
it might be unsafe.. 

>
> Re: 3) I'll try to build my own error page for 503. Is there a way
> to run some code to notify the administrator that this has happened?

I guess you can make "php" page as for 503 error that simply sends an email.

>
> Re: 4) I'm originally from the Windows world so I don't know how
> to make my own segfault handler on Linux yet. I'll try to find out.
> Let's say I had my own segfault handler and it caught the crash,
> what would I do in the handler code? I suppose the process is already
> in an faulty state when that happens, and keeping it running would not
> be ideal. So I should quit it and let Apache reload the process?

well, if you make your own sigterm handler, it gives you an opportunity to 
"log" the error from inside, e.g. to track the file and line which lead to 
the problem. moreover, you can still try to finalize some internal processes 
before exiting. finally, you should make exit(11), such way informing fastcgi 
module, that the program has encountered segfault.

if you make your app in C, signal handling is easy. in "main", initialize your 
signal handler:

    if (signal(SIGSEGV, sigsegv_handler) == SIG_ERR){
        printf("An error occured while setting a signal handler.\n");
        exit(0);
    }

and further define the sigsegv_handler function

void sigsegv_handler(int signal){
//do whatever
 exit(11); //or actually here you can specify any other reason for exiting
}


best,
j.

___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.