/
index.html
183 lines (137 loc) · 4.42 KB
/
index.html
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!doctype html>
<html>
<head>
<title>nginx-perl</title>
<meta name="description" content="Full-featured perl support for nginx" />
</head>
<body>
<div class="row">
<div class="w100 centr cl pagepadtop blockpadbottom rl hlogo">
<div class="ab m2 hlogo">
<img src="nginx-perl-big.gif" border="0"
alt="nginx-perl" />
</div>
</div>
<div class="w100 centr cl blockpadtop blockpadbottom"><div class="w80">
<p>Full-featured perl support for nginx.</p>
<p>
Nginx-perl brings asynchronous functions and other useful features
into embedded perl to turn it into nice and powerful perl web server.
</p>
<h3>Download</h3>
<p>
<a href="nginx-perl-1.1.17.1.tar.gz">nginx-perl-1.1.17.1.tar.gz</a> 678 K
</p>
<h3>Github</h3>
<p><a href="https://github.com/zzzcpan/nginx-perl" target="_blank">zzzcpan/nginx-perl</a></p>
<h3>Changes</h3>
<p>
<a href="https://raw.github.com/zzzcpan/nginx-perl/master/CHANGES.perl">CHANGES.perl</a> (nginx-perl)<br/>
<a href="https://raw.github.com/zzzcpan/nginx-perl/master/CHANGES">CHANGES</a> (nginx)
</p>
<h3>Documentation</h3>
<ul class="nls">
%% DOCUMLI %%
</ul>
<h3>Features</h3>
<ul class="nls">
<li> - full official nginx perl API</li>
<li> - asynchronous connections (ngx_connector, ngx_reader, ngx_writer)</li>
<li> - timer (ngx_timer)</li>
<li> - SSL (ngx_ssl_handshaker)</li>
<li> - resolver (ngx_resolver)</li>
<li> - access handlers (perl_access)</li>
<li> - app handlers (perl_app)</li>
<li> - configuration level eval (perl_eval)</li>
<li> - perl_init_worker, perl_exit_worker handlers</li>
<li> - logging functions (ngx_log_*)</li>
<li> - client connection takeover for websockets, etc</li>
</ul>
<h3>Synopsis</h3>
<pre> use Nginx;
# nginx's asynchronous resolver
# "resolver 1.2.3.4;" in nginx-perl.conf
ngx_resolver "www.google.com", 15, sub {
my (@IPs) = @_;
if ($!) {
my ($errcode, $errstr) = @_;
ngx_log_error $!, "Cannot resolve google's IP: $errstr";
}
};
# timer
ngx_timer 5, 0, sub {
ngx_log_notice 0, "5 seconds gone";
};
# asynchronous connections
# with explicit flow control
ngx_connector "1.2.3.4", 80, 15, sub {
if ($!) {
ngx_log_error $!, "Connect error: $!";
return NGX_CLOSE;
}
my $c = shift; # connection
my $wbuf = "GET /\x0d\x0a";
my $rbuf;
ngx_writer $c, $wbuf, 15, sub {
if ($!) {
ngx_log_error $!, "Write error: $!";
return NGX_CLOSE;
}
return NGX_READ;
};
ngx_reader $c, $rbuf, 0, 0, 15, sub {
if ($! && $! != NGX_EOF) {
ngx_log_error $!, "Read error: $!";
return NGX_CLOSE;
}
if ($! == NGX_EOF) {
ngx_log_info 0, "response length: " . length ($rbuf);
return NGX_CLOSE;
}
return NGX_READ; # no errors - read again
};
return NGX_WRITE; # what to do on connect
};
# SSL handshake
ngx_connector "1.2.3.4", 80, 15, sub {
...
my $c = shift;
ngx_ssl_handshaker $c, 15, sub {
...
ngx_writer $c, $wbuf, 15, sub {
...
};
ngx_reader $c, $rbuf, 0, 0, 15, sub {
...
};
return NGX_WRITE;
};
return NGX_SSL_HANDSHAKE;
};
# asynchronous response
# via HTTP API
sub handler {
my ($r) = shift;
$r->main_count_inc;
ngx_resolver "www.google.com", 15, sub {
$r->send_http_header ('text/html');
unless ($!) {
lcoal $, = ', ';
$r->print ("OK, @_\n");
} else {
$r->print ("FAILED, $_[1]\n");
}
$r->send_special (NGX_HTTP_LAST);
$r->finalize_request (NGX_OK);
};
return NGX_DONE;
}
# and more...
</pre>
</div></div>
<div class="w100 centr cl blockpadtop pagepadbottom">
<p>© 2012 Alexandr Gomoliako</p>
</div>
</div>
</body>
</html>