-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME
111 lines (79 loc) · 2.89 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
104
105
106
107
108
109
110
= fcgi - FastCGI library for Ruby
Version 0.8.9
== Depends
=== C version
* ((<libfcgi|URL:http://www.fastcgi.com/#TheDevKit>))(FastCGI Developer's Kit)
=== Pure Ruby Version
* StringIO
== Install
$ ruby install.rb config
(Pure Ruby Version: ruby install.rb config --without-ext)
(Some systems need: ruby install.rb config -- --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib)
$ ruby install.rb setup
# ruby install.rb install
== Usage
=== Class Method
--- FCGI.accept
Returns FCGI instance
--- FCGI.each
--- FCGI.each_request
--- FCGI.is_cgi?
--- FCGI.each_cgi
Automatically detects whether this program is running under the FastCGI
environment, and generates a 'CGI' type object for each request. Also
installs signal handlers for graceful handling of SIGPIPE (which may
occur if a client gives up on a request before it is complete) and
SIGUSR1 (generated by Apache for a 'graceful' exit)
If you are using the HTML output methods you can also pass the HTML type
e.g. FCGI.each_cgi('html3') do ... end
However, you should beware that the CGI library is quite slow when
used in this way, as it dynamically adds a large number of methods
to itself each time a new instance is created.
=== Instance Method
--- FCGI#finish
Finish
--- FCGI#in
Returns Stream or StringIO
--- FCGI#out
Returns Stream or StringIO
--- FCGI#err
Returns Stream or StringIO
--- FCGI#env
Returns Environment(Hash)
== Sample
Using the FastCGI native interface:
#!/usr/bin/ruby
require "fcgi"
FCGI.each {|request|
out = request.out
out.print "Content-Type: text/plain\r\n"
out.print "\r\n"
out.print Time.now.to_s
request.finish
}
Using the CGI-compatible interface, which works both as a standalone CGI
and under FastCGI with no modifications:
#!/usr/bin/ruby
require "fcgi"
FCGI.each_cgi {|cgi|
name = cgi['name'][0]
puts cgi.header
puts "You are #{name} " if name
puts "Connecting from #{cgi.remote_addr}"
}
Note: you can't reference CGI environment variables using ENV when under
FastCGI. It is recommended that you use the CGI-generated methods, e.g.
cgi.remote_addr as above.
If you need to access environment variables directly, perhaps extra ones set
in your Apache config, then use cgi.env_table['REMOTE_ADDR'] instead. This
isn't quite as portable because env_table is a private method in the
standard CGI library.
== License
* ((<URL:http://www.ruby-lang.org/ja/LICENSE.txt>)) (Japanese)
* ((<URL:http://www.ruby-lang.org/en/LICENSE.txt>)) (English)
== Copyright
fcgi.c 0.1 Copyright (C) 1998-1999 Network Applied Communication Laboratory, Inc.
0.8 Copyright (C) 2002 MoonWolf <moonwolf@moonwolf.com>
fastcgi.rb 0.7 Copyright (C) 2001 Eli Green
fcgi.rb 0.8 Copyright (C) 2002 MoonWolf <moonwolf@moonwolf.com>
fcgi.rb 0.8.5 Copyright (C) 2004 Minero Aoki