Cleanup Makefile.PL
[catagits/fcgi2.git] / perl / threaded.PL
CommitLineData
34bfd355 1use Config;
2
3open OUT, ">threaded.fpl";
4print OUT "#!$Config{perlpath}\n";
5print OUT while <DATA>;
6close OUT;
7chmod 0755, "threaded.fpl";
8__END__
9
10use FCGI;
11use Thread;
cebfd7c4 12use IO::Handle;
34bfd355 13
14use constant THREAD_COUNT => 5;
15
16sub 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
49for ($t = 1; $t < THREAD_COUNT; ++$t) {
50 new Thread \&doit, $t;
51}
52doit(0);