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; |
cebfd7c4 |
12 | use IO::Handle; |
34bfd355 |
13 | |
14 | use constant THREAD_COUNT => 5; |
15 | |
16 | sub doit { |
17 | my $k = shift; |
18 | my %env; |
cebfd7c4 |
19 | my $in = new IO::Handle; |
20 | my $out = new IO::Handle; |
21 | my $err = new IO::Handle; |
34bfd355 |
22 | |
6ff77aff |
23 | my $request = FCGI::Request($in, $out, $err, \%env); |
34bfd355 |
24 | |
6ff77aff |
25 | while ($request->Accept() >= 0) { |
34bfd355 |
26 | print $out |
27 | "Content-type: text/html\r\n", |
28 | "\r\n", |
6ff77aff |
29 | "<title>FastCGI Hello! (multi-threaded perl, fcgiapp library)</title>", |
30 | "<h1>FastCGI Hello! (multi-threaded perl, fcgiapp library)</h1>", |
34bfd355 |
31 | "Request counts for ", THREAD_COUNT ," threads ", |
32 | "running on host <i>$env{SERVER_NAME}</i><P><CODE>"; |
33 | |
34bfd355 |
34 | { |
35 | lock(@count); |
cebfd7c4 |
36 | |
37 | ++$count[$k]; |
38 | |
34bfd355 |
39 | for(my $i = 0; $i < THREAD_COUNT; ++$i) { |
40 | print $out $count[$i]; |
41 | print $out " "; |
42 | } |
43 | } |
d8cc97fb |
44 | $request->Flush(); |
34bfd355 |
45 | sleep(1); |
46 | } |
47 | } |
48 | |
49 | for ($t = 1; $t < THREAD_COUNT; ++$t) { |
50 | new Thread \&doit, $t; |
51 | } |
52 | doit(0); |