Class: PHPRPC::SCGIServer
- Inherits:
-
BaseServer
- Object
- BaseServer
- PHPRPC::SCGIServer
- Defined in:
- lib/phprpc/scgi_server.rb
Overview
class SCGIProcessor
Instance Attribute Summary
Attributes inherited from BaseServer
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SCGIServer
constructor
A new instance of SCGIServer.
- #start ⇒ Object
Methods inherited from BaseServer
Constructor Details
#initialize(options = {}) ⇒ SCGIServer
Returns a new instance of SCGIServer.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/phprpc/scgi_server.rb', line 69 def initialize( = {}) super() @options = { :host => '0.0.0.0', :port => 9999, :maxconns => 2**30 - 1, :session_mode => :file, :path => "/", :expire_after => 1800, }.update() @opts = OptionParser.new @opts. = "Usage: #{@opts.program_name} scgi [options]" @opts.separator "" @opts.separator "Server options:" @opts.on('-a', '--address IP', String, "Bind SCGI to the specified ip.", "(default: #{@options[:host]})") { |ip| @options[:host] = ip } @opts.on('-p', '--port PORT', Integer, "Run SCGI on the specified port.", "(default: #{@options[:port]})") { |port| @options[:port] = port } @opts.on('-l', '--logfile FILE', String, "Where to write log messages.") { |file| @options[:logfile] = file } @opts.on('-n', '--maxconns NUM', Integer, "Allow this many max connections,", "more than this are redirected to /busy.html", "(default: #{@options[:maxconns]})") { |num| @options[:maxconns] = num } @opts.separator "" @opts.separator "Session options:" @opts.on('-s', '--session-mode MODE', [:file, :memcache, :pool], "Select Session mode (file, memcache, pool)", "(default: #{@options[:session_mode].to_s})") { |mode| @options[:session_mode] = mode } @opts.on('-e','--expire-after TIME', Integer, "Session expire after (default: #{@options[:expire_after]})") { |time| @options[:expire_after] = time } @opts.on('-m','--memcache_server SERVER', String, "Memcache server used by session in", "memcache mode (default: localhost:11211)") { |server| @options[:memcache_server] = server } @opts.on('--prefix PATH', String, "Mount the PHPRPC Server under PATH", "(start with /)") { |path| @options[:path] = path } @opts.separator "" @opts.separator "Common options:" @opts.on_tail('-D', '--debug', "Set debbuging on") { self.debug = true } @opts.on_tail('-?', '-h', '--help', "Show this help message.") { puts @opts; exit } begin @opts.parse!(ARGV) rescue OptionParser::ParseError puts @opts exit end end |
Instance Method Details
#start ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/phprpc/scgi_server.rb', line 105 def start app = self if [:memcache, :pool].include?(@options[:session_mode]) then begin require 'rack' if @options[:session_mode] == :memcache then app = Rack::Session::Memcache.new(self, @options) else app = Rack::Session::Pool.new(self, @options) end rescue Exception app = self end end puts "## PHPRPC SCGI Server 3.0.0" puts "## Listening on #{@options[:host]}:#{@options[:port]}, CTRL+C to stop" begin SCGIProcessor.new(@options.update({:app => app})).listen rescue SystemExit exit rescue Exception => e puts "## #{@options[:host]}:#{@options[:port]} #{e.}" puts @opts exit end end |