Commit | Line | Data |
34bfd355 |
1 | use Config; |
2 | |
3 | open OUT, ">threaded.fpl"; |
4 | print OUT "#!$Config{perlpath}\n"; |
5 | print OUT while <DATA>; |
6 | close OUT; |
7 | chmod 0755, "threaded.fpl"; |
8 | __END__ |
9 | |
10 | use FCGI; |
11 | use Thread; |
12 | |
13 | use constant THREAD_COUNT => 5; |
14 | |
15 | sub doit { |
16 | my $k = shift; |
17 | my %env; |
18 | my $in = do { local *FH }; |
19 | my $out = do { local *FH }; |
20 | my $err = do { local *FH }; |
21 | |
22 | my $request = FCGI::request(); |
23 | |
24 | while ($request->accept(\$in, \$out, \$err, \%env) >= 0) { |
25 | print $out |
26 | "Content-type: text/html\r\n", |
27 | "\r\n", |
28 | "<title>FastCGI Hello! (multi-threaded C, fcgiapp library)</title>", |
29 | "<h1>FastCGI Hello! (multi-threaded C, fcgiapp library)</h1>", |
30 | "Request counts for ", THREAD_COUNT ," threads ", |
31 | "running on host <i>$env{SERVER_NAME}</i><P><CODE>"; |
32 | |
33 | ++$count[$k]; |
34 | |
35 | { |
36 | lock(@count); |
37 | for(my $i = 0; $i < THREAD_COUNT; ++$i) { |
38 | print $out $count[$i]; |
39 | print $out " "; |
40 | } |
41 | } |
42 | $request->flush(); |
43 | sleep(1); |
44 | } |
45 | } |
46 | |
47 | for ($t = 1; $t < THREAD_COUNT; ++$t) { |
48 | new Thread \&doit, $t; |
49 | } |
50 | doit(0); |