Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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

by flexvault (Monsignor)
on Jan 22, 2016 at 17:52 UTC ( [id://1153394] : note . print w/replies, xml ) Need Help??

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

Hello exilepanda,

I re-read your posts several times, and I think this is what you're trying to do:

WebServer --> Client --> 2nd Client --> %ENV input
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . V
WebServer <-- Client <-- 2nd Client <-- HTML output

You want the WebServer to call a Client (CGI-script) to send the 'Todo' work to a 2nd Client ( Perl script ) that actually does the processing and then send the result (HTML output) back to the WebServer.

If this isn't what you want to do, then don't bother reading the rest of my post :-)

I have done this where we used Apache2 web-servers to call a small cgi-script which sent/received the data over sockets to a remote server(s) to process the 'Todo' work. If you do a super search on "Persistent Perl", you may get some ideas on "how" to accomplish this.

If this is what you're looking for, then you can ask some better questions and get some much better answers.

Hope this helps...Ed


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

Replies are listed 'Best First'.
Re^2: How a web server sending data to a CGI perl script ?
by exilepanda (Friar) on Jan 25, 2016 at 05:30 UTC
    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 ?

      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!


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

      $ 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 ?