class MOD_FCGI < FCGI 
Author Message
 class MOD_FCGI < FCGI

rubyists-

i've collected some usefull examples and added some signal handling to the
fcgi package written by moon wolf.  if any one has experience using fcgi out
there i appreciate any comments.  highlights are

    * reload any application using 'kill -HUP pid' w/o{*filter*} apache
    * gracefull shutdown from confusing SIGUSR1/SIGHUP combo sent by
      apache/mod_fastcgi to fcgi programs
    * clean exit on 'kill -TERM pid'
    * each method which provides a CGI object

eg of use

   MOD_FCGI.each('html3') do |cgi|
      content = ''
      cgi.env_table.each do |k,v|
        content << "#{k} -> #{v}<br>\n"
      end
      cgi.out { cgi.html { cgi.body { content } } }
  end

ps.  this is named MOD_FCGI because, AFAIK this signal handling is specific to
apache's mod_fastcgi

file : mod_fcgi.rb
----CUT----
require 'fcgi'
require 'cgi'
require 'ftools'

class MOD_FCGI < FCGI

  class Log < File
    def tmpnam basename = nil,
               tmpdir = ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp'
      if $SAFE > 0 and tmpdir.tainted?
        tmpdir = '/tmp'
      end
      basename ||= File.basename $0
      n = 0
      while true
        begin
          path = sprintf('%s/%s%d.%d', tmpdir, basename, $$, n)



            break
          end
        rescue
          raise "cannot generate tempfile `%s'" % path if n >= 16
        end
        n += 1
      end
      path
    end
    def initialize path = tmpnam, mode = 'w+', &block
      super path, mode, &block

      self.sync = true
    end
  end

  # enable CGI to bootstrap off of an FCGI request
  class CGI < ::CGI
    class << self
      def remove_params
        if (const_defined?(:CGI_PARAMS))
          remove_const(:CGI_PARAMS)
          remove_const(:CGI_COOKIES)
        end
      end
    end
    def initialize(request, *args)
      self.class.remove_params

      super (*args)

    end
    def args

    end
    def env_table

    end
    def stdinput

    end
    def stdoutput

    end
  end

  # initialize mod_fcgi




  class << self
    def handle_request

      yield if block_given?
      ensure

    end

    def install_traps

      # user signal to reload application
      # does a clean shutdown after which
      # the fcgi_pm will reload of source file
      trap ('SIGHUP') do




          else

            exit
          end
        end
      end

      # sent from apache to do clean shutdown
      # note that a sigterm could be sent from fcgi_pm
      # AFTER this!  we handle only one of them!
      trap ('SIGUSR1') do




          else

            exit
          end
        end
      end

      # see above note.
      # when no other signals pedning, simply exit quickly
      trap ('SIGTERM') do



          exit
        end
      end

      # sent from mod_fcgi when client aborts request
      # we simply ignore this for now, although some smarts could be
      # added to abort the present request and resume accepting...
      trap ('SIGPIPE') do
        # nothing
      end


    end

    def each (*args)
      install_traps
      while request = accept
        handle_request {
          if block_given?
            yield (CGI.new (request, *args))
            request.finish
          end
        }

      end
    end

    alias each_request each
  end
end
----CUT----

-a

--

 ====================================
 | Ara Howard
 | NOAA Forecast Systems Laboratory
 | Information and Technology Services
 | Data Systems Group
 | R/FST 325 Broadway
 | Boulder, CO 80305-3328

 | Phone:  303-497-7238
 | Fax:    303-497-7259
 ====================================



Sun, 31 Jul 2005 22:39:05 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. ADVICE <<<<<<<<<<<<<<<<<<<-----------EASY ---------------

2. I SEARCH ASSEMBLER CODERS <<<<<<<<<<<<

3. class << self

4. Mixin using append_features and class<<self do not work together

5. class << self question

6. class << self

7. Fortran compiler source code <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

8. ><><><><>Heeeeeeeeeeeeeeelp on INT 14!><><><><><>

9. Array default values, << and <<=

10. >>>>>>>>>>>>>>>>>>>HEY!<<<<<<<<<<<<<<<<<<<<<<<

11. <><><> FLOODFILL <><><>

12. >>>HELP, DECOMPILER<<<

 

 
Powered by phpBB® Forum Software