in reply to How a web server sending data to a CGI perl script ?
and client# server.pl use strict; use warnings; use POSIX (); my $cgis = 0; $SIG{CHLD} = sub { while ( waitpid( -1, POSIX::WNOHANG ) > 0 ) { $cgis -= 1; } }; while (1) { print '(Ctrl-D to quit)> '; my $request = <STDIN>; last if not defined $request; chomp $request; print "Server: about to fork a CGI client\n"; $ENV{foo} = 'bar'; # use some real $ENV{baz} = 'quux'; # CGI variables pipe my ( $child_stdin, $input_to_child, ); pipe my ( $output_from_child, $child_stdout, ); my $pid = fork; if ( $pid == 0 ) { close $input_to_child; close $output_from_child; open STDIN, '<&', $child_stdin; open STDOUT, '>&', $child_stdout; exec {'perl'} 'perl', 'client.pl'; } else { close $child_stdin; close $child_stdout; print "Server: forked process $pid\n"; $cgis += 1; print $input_to_child $request; close $input_to_child; print "Server: reading child response\n", <$output_from_child>; } } print "Server exiting, remaining children: $cgis\n";
# client.pl use strict; use warnings; my $input = <STDIN>; print <<END This is a pseudo-CGI client reporting. Process number $$ Got input "$input" \$ENV{foo} is "$ENV{foo}" \$ENV{baz} is "$ENV{baz}" End of report END
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How a web server sending data to a CGI perl script ?
by Anonymous Monk on Jan 21, 2016 at 13:38 UTC | |
by Anonymous Monk on Jan 21, 2016 at 14:50 UTC | |
|
Re^2: How a web server sending data to a CGI perl script ?
by exilepanda (Friar) on Jan 22, 2016 at 02:28 UTC |