Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: How a web server sending data to a CGI perl script ?

by exilepanda (Pilgrim)
on Jan 25, 2016 at 05:30 UTC ( #1153537=note: print w/replies, xml ) Need Help??


in reply to Re: How a web server sending data to a CGI perl script ?
in thread How a web server sending data to a CGI perl script ?

Thanks Ed, I might want to do the things as your described ( 2nd client ), but the fact is that I already stuck at the first client.

From a CGI script perspective, when it's triggered by the server, the script will naturally have all relevant %ENV variables like REMOTE_ADDR, COOKIE, REQUEST_METHOD etc.

So that my very root question is how these $ENV variables are sent to the CGI script before the first line of code in the CGI script is run ?

  • Comment on Re^2: How a web server sending data to a CGI perl script ?

Replies are listed 'Best First'.
Re^3: How a web server sending data to a CGI perl script ?
by flexvault (Monsignor) on Jan 25, 2016 at 16:03 UTC

    Hello exilepanda,

    If you do it the way I described, the %ENV variables are already set-up for you. Do not touch the %ENV, but copy the %ENV to a temp hash. And remember you still need the GET / POST data ( the actual $Todo work ) from the WebServer. ( Example ).

    my $Todo = ...; # Data sent via GET or POST from browser via We +bServer my $environment = ''; foreach my $env ( keys %ENV ) { $environment .= "$env\t$ENV{$env}\n"; } my $send = pack("N",length($environment) ) . $environment . pack( +"N",length($Todo) ) . $Todo; my $ret = send_data( $svr, \$send ); # Send to processing Perl s +cript
    Now the second client has the environment of the WebSever, and it's own %ENV from Perl. The processing client uses %TempENV for WebServer info and it's own %ENV if it needs it.

    It's clean and you don't have to get into the error handling of the WebServer.

    Good Luck!

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

Re^3: How a web server sending data to a CGI perl script ?
by Anonymous Monk on Jan 25, 2016 at 07:26 UTC
    $ cat shabba for my $key ( grep /perl/i , keys %ENV ){ print qq{ $key $ENV{$key}\n} +; } $ perl shabba PERL_MB_OPT --config installhtmldir= --binhtml= $ perl -e " $ENV{PERL_SHABBA}=666; system $^X, q{shabba}; " PERL_SHABBA 666 PERL_MB_OPT --config installhtmldir= --binhtml= --config installht +mldir= --binhtml= $ perl shabba PERL_MB_OPT --config installhtmldir= --binhtml=
      Oh Wow!! Surprised!!! Great demonstration and works perfectly! And I just notice the system() or the backticks ( the right tool for my case ) are actually kind of fork thing... which is the "how" that I exactly asking! Thanks man!

      Though.. what still puzzle me is how do you leave the <STDIN> open for the CGI to read() in this code pattern ?

        Its not a pattern, just shows %ENV is inherited from parent process

        Its one part of what HTTP::Request::AsCGI does, STDIN... stuff is the other part

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1153537]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2020-02-18 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (75 votes). Check out past polls.

    Notices?