Commit | Line | Data |
b3029f84 |
1 | #!/usr/bin/perl |
87197739 |
2 | use strict; |
3 | use warnings; |
4 | use threads; |
5 | use threads::shared; |
34bfd355 |
6 | |
87197739 |
7 | use FCGI qw[]; |
8 | use IO::Handle qw[]; |
34bfd355 |
9 | |
10 | use constant THREAD_COUNT => 5; |
11 | |
87197739 |
12 | my @count : shared = (0, (0) x THREAD_COUNT); |
13 | |
14 | sub worker { |
34bfd355 |
15 | my $k = shift; |
16 | my %env; |
87197739 |
17 | my $in = IO::Handle->new; |
18 | my $out = IO::Handle->new; |
19 | my $err = IO::Handle->new; |
34bfd355 |
20 | |
6ff77aff |
21 | my $request = FCGI::Request($in, $out, $err, \%env); |
34bfd355 |
22 | |
87197739 |
23 | while ($request->Accept >= 0) { |
24 | print $out |
25 | "Content-type: text/html\r\n", |
26 | "\r\n", |
27 | "<title>FastCGI Hello! (multi-threaded perl, fcgiapp library)</title>", |
28 | "<h1>FastCGI Hello! (multi-threaded perl, fcgiapp library)</h1>", |
29 | "Request counts for ", THREAD_COUNT ," threads ", |
30 | "running on host <i>$env{SERVER_NAME}</i>"; |
31 | |
32 | { |
33 | lock(@count); |
34 | |
35 | ++$count[$k]; |
36 | |
37 | for(my $i = 1; $i <= THREAD_COUNT; $i++) { |
38 | print $out $count[$i]; |
39 | print $out " "; |
40 | } |
41 | } |
42 | $request->Flush; |
43 | sleep(1); |
34bfd355 |
44 | } |
45 | } |
46 | |
87197739 |
47 | $_->join for map { threads->create(\&worker, $_) } 1..THREAD_COUNT; |
48 | |