Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by exilepanda (Pilgrim)
on Jan 21, 2016 at 09:39 UTC ( #1153258=note: print w/replies, xml ) Need Help??


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

In short, "How"?

I read the RFC recommended,I know what I should prepare (and I already knew) for my script, but the question is how to send it to the script.

Do I send them via a pipe ? or command line with -??? switches, or what ? As far as web servers I've explored, I notice the only thing that need to tell the server is where the interpreter is (, and associate the application/type with file name extension). So what's the magic between ?

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

Replies are listed 'Best First'.
Re^5: How a web server sending data to a CGI perl script ?
by Corion (Pope) on Jan 21, 2016 at 09:51 UTC

    As you've read the RFC, maybe you can tell us what parts of chapter 3, Invoking the Script you've already implemented, and where your server still fails.

    Update: Chapter 4.1, Request Meta-Variables tells me:

    Meta-variables contain data about the request passed from the server to the script, and are accessed by the script in a system-defined manner.

    The traditional system-defined manner is using the environment (%ENV) to pass these values. See also chapter 7, which discusses the different operating systems and their system-defined ways of communicating the variables to the child process.

      In fact, I think that's nothing to do with RFC. A CGI script can be in Perl, Python, PHP, or whatever, it's the spec only, which is a "WHAT" but I am asking "HOW".

      Consider I have already prepare everything (is needed for me at this moment, actually), but as said in my OP, the limitation is I have to do all the rest within my server's code. My server can communicate with the browser by all means.

      I don't know "the how" is how to pass the parameters that I've prepared to my target CGI script, so when my CGI script got triggered, it's just naturally have all the %ENV variables ready or a opened STDIN is ready for read().

Re^5: How a web server sending data to a CGI perl script ?
by Anonymous Monk on Jan 21, 2016 at 10:18 UTC

    I read the RFC recommended,I know what I should prepare (and I already knew) for my script, but the question is how to send it to the script.

    client makes a request through socket , your server reads headers, then

    Populate a local %ENV

    dispatches/calls/invokes a process ,

    through pipe, fork, whatever, see perlipc, Capture::Tiny

    put http request BODY on STDIN

    Collect output from STDOUT

    log errors from STDERR

    After timeout, or whatever, return/generate/forward a return HTTP request back on socket to the client

    I already linked examples in Re: How a web server sending data to a CGI perl script ?

      Thanks and I am still reading.... I can feel something and it's insightful indeed. Would be glad to hear more from your advise though :

      1. Do you think rather send out the data to an external script, import the external code into the server and run it is a better approach (eg. require "script.pl") ?

      2. Can you tell if when a web server claims it supports a certain language, it does have to implement something ( not just command line ) to prepare the environment ( meta ) variables for that particular language ?

        1. Do you think rather send out the data to an external script, import the external code into the server and run it is a better approach (eg. require "script.pl") ?

        Sure its a better approach (hint CGI::Compile/ ), for perl, its called PSGI as implemented by Plack

        2. Can you tell if when a web server claims it supports a certain language, it does have to implement something ( not just command line ) to prepare the environment ( meta ) variables for that particular language ?

        What "web server" are claiming what kind of support?

        Yeah, question is kinda vague, claimed support can be anything, from what mod_perl does (full control) to what to merely support for better-than-CGI like WSGI, PSGI, Rack, JSGI, SCGI...

Log In?
Username:
Password:

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

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










    Results (104 votes). Check out past polls.

    Notices?