[WIN32] Raise SIGTERM from the ShutdownRequestThread to emulate
[fcgi2.git] / perl / threaded.PL
blobf8a8c62fd77b4baa40fc9b03338a7c07eac93294
1 use Config;
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__
10 use FCGI;
11 use Thread;
12 use IO::Handle;
14 use constant THREAD_COUNT => 5;
16 sub doit {
17     my $k = shift;
18     my %env;
19     my $in = new IO::Handle;
20     my $out = new IO::Handle;
21     my $err = new IO::Handle;
23     my $request = FCGI::Request($in, $out, $err, \%env);
25     while ($request->Accept() >= 0) {
26         print $out
27            "Content-type: text/html\r\n",
28            "\r\n",
29            "<title>FastCGI Hello! (multi-threaded perl, fcgiapp library)</title>",
30            "<h1>FastCGI Hello! (multi-threaded perl, fcgiapp library)</h1>",
31            "Request counts for ", THREAD_COUNT ," threads ",
32            "running on host <i>$env{SERVER_NAME}</i><P><CODE>";
34         {
35             lock(@count);
37             ++$count[$k];
39             for(my $i = 0; $i < THREAD_COUNT; ++$i) {
40                 print $out $count[$i];
41                 print $out " ";
42             }
43         }
44         $request->Flush();
45         sleep(1);
46     }
49 for ($t = 1; $t < THREAD_COUNT; ++$t) {
50     new Thread \&doit, $t;
52 doit(0);