title: How do I get killed using Perl FCGI?
body: <p>I'm having a little problem with nginx and the Perl FCGI module. I have a long operation in my FCGI program that may outlive the server (or the user on the server) on the other end of the Unix socket I'm using to communicate FCGI. I need the FCGI accept() loop in my program to break if the FCGI request is closed. I tried installing INT, TERM, etc signal handlers, but they do nothing, since the only communication between nginx and my program happens over the FCGI socket, AFAIK.</p>
  
  <p>I also tried <a href="https://stackoverflow.com/questions/1302209/how-do-i-ping-a-fastcgi-server">this</a> but there's no way that I can see to use the FCGI module in Perl to send raw data to or from nginx over the FCGI socket. Is there a way I can do it without modifying the FCGI module to have a "ping" function?</p>
  
  <p>The basic problem is that my program does not know if nginx has terminated the FCGI request.</p>
  
  <p>Example:</p>
  
  <pre><code>#!/usr/bin/perl -w
  use strict;
  use FCGI;
  
  my $fcgi_socket = FCGI::OpenSocket( '/tmp/test.socket', 100000 );
  my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, $fcgi_socket);
  REQUEST: while($request-&gt;Accept() &gt;= 0) {
      #begin handling request
      my $result = '';
      while (1) { #or select(), etc
          if (somehow check whether the fcgi $request is still live) {
              next REQUEST;
          }
          #check for results, set $result if done
      }
      print $result;
  }
  </code></pre>