Re: Eagle Book - mod_hello.c, hello.pl :)
On Mon, 29 Nov 1999, Michael Dearman wrote: ... When looking at http_config.h at the handler_rec structure, the elements don't seem to match the way they're used in the example in the book. Going to the book site, the src's for the examples are NOT available. *shrug* all of the book source and then some is available from the site, there's a link on the homepage. it includes an apxs/Makefile for building the C modules.
Re: Eagle Book - mod_hello.c, hello.pl :)
On Tue, 30 Nov 1999, Ofer Inbar wrote: Michael Dearman [EMAIL PROTECTED] wrote: I've come close to figuring this one out buy following some of the questions I've seen here. But... H1Hello $ENV{REMOTE_HOST}/H1 The remote host doesn't show. Printing out the %ENV, it tain't there. But where does Perl get it. From CGI.pm (which is installed) or where? %ENV is the environment. CGI uses the environment to pass values from the web server to the CGI program. If your script was running under CGI, the web server would put REMOTE_HOST, and other things, in the environment, before forking to run your script. But you're not using CGI, you're using mod_perl. The server isn't setting CGI environment variables This is not quite true. The server does sets the %ENV to emulate mod_cgi in order to server modules like CGI.pm that expects these variables to be available for their convenience. This setting adds an overhead, which you might consider to reduce. For more info read: http://perl.apache.org/guide/performance.html#PerlSetupEnv_Off This is an easy prove that %ENV is set (while not all variables are present as with mod_cgi, particularly REMOTE_HOST isn't there...) PerlModule MyEnv Location /env SetHandler perl-script PerlHandler MyEnv /Location package MyEnv; use Apache; use Apache::Constants; sub handler{ my $r = shift; print $r-send_http_header("text/plain"); print map {"$_ = $ENV{$_}\n"} keys %ENV; return OK; } 1; http://localhost/env prints: SERVER_SOFTWARE = Apache/1.3.10-dev (Unix) mod_perl/1.21_01-dev DOCUMENT_ROOT = /home/httpd/docs GATEWAY_INTERFACE = CGI-Perl/1.1 REMOTE_ADDR = 127.0.0.1 SERVER_PROTOCOL = HTTP/1.0 SERVER_SIGNATURE = ADDRESSApache/1.3.10-dev Server at inx006.iil.intel.com Port 80/ADDRESS REQUEST_METHOD = GET QUERY_STRING = HTTP_USER_AGENT = Mozilla/4.7 [en] (X11; I; Linux 2.2.12-20 i686) PATH = /bin:/usr/bin HTTP_CONNECTION = Keep-Alive HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */* REMOTE_PORT = 3167 SERVER_ADDR = 127.0.0.1 HTTP_ACCEPT_LANGUAGE = en MOD_PERL = mod_perl/1.21_01-dev SCRIPT_NAME = /env SCRIPT_FILENAME = /home/httpd/docs/env HTTP_ACCEPT_ENCODING = gzip SERVER_NAME = inx006.iil.intel.com REQUEST_URI = /env HTTP_ACCEPT_CHARSET = iso-8859-1,*,utf-8 SERVER_PORT = 80 HTTP_HOST = localhost SERVER_ADMIN = [EMAIL PROTECTED] and forking to run your script. Your script is being run by a code module that is part of the web server. You need to use Apache specific calls to get the information you need from the web server. mod_perl makes this easy to do using the "Apache request object": $request = Apache-request; $connection = $request-connection; $remote_ip = $connection-remote_ip; Read more about the request object in the mod_perl documentation, to find out how to ask it for the other kinds of information a CGI script normally gets out of the environment. Remember, mod_perl is not CGI (although with Apache::Registry it can look quite similar to CGI) -- Cos (Ofer Inbar) -- [EMAIL PROTECTED] [EMAIL PROTECTED] -- Exodus Professional Services -- [EMAIL PROTECTED] "This may seem a bit weird, but that's okay, because it is weird." -- Larry Wall in perlref(1) man page, Perl 5.001 ___ Stas Bekman mailto:[EMAIL PROTECTED]www.singlesheaven.com/stas Perl,CGI,Apache,Linux,Web,Java,PC at www.singlesheaven.com/stas/TULARC www.apache.org www.perl.com == www.modperl.com || perl.apache.org single o- + single o-+ = singlesheavenhttp://www.singlesheaven.com
Re: Eagle Book - mod_hello.c, hello.pl :)
Gerd Kortemeyer wrote: Michael Dearman [EMAIL PROTECTED] wrote: I've come close to figuring this one out buy following some of the H1Hello $ENV{REMOTE_HOST}/H1 Stas Bekman wrote: This is an easy prove that %ENV is set (while not all variables are present as with mod_cgi, particularly REMOTE_HOST isn't there...) Yes, there's a 'printenv' script in the cgi-bin dir. From http://www.apache.org/docs/upgrading_to_1_3.html REMOTE_HOST CGI variable changed. In Apache 1.2 and earlier, the REMOTE_HOST environment variable made available to CGI scripts was set to either the full DNS name of the client, or else to the client's IP address if the name was not known. This behaviour differed from that specified by the CGI specification, which defines this variable as being NULL if the name isn't known. In Apache 1.3, we have made this correction. REMOTE_ADDR always contains the client's IP address, but REMOTE_HOST is only defined when the server has been able to determine the client's DNS name. I think that is what you are seeing, rather than any problem with the environment in general. - Gerd. [the 's aren't correct. Tried to reformat to make clearer and properly acknowledge the help] Thanks!! That was it. Specifically - I don't have DNS set up on my home network. REMOTE_ADDR did the trick. And thanks for pointing out those resources. Should help with other problems with examples in the Book. *Saaalute* Michael Dearman
Re: Eagle Book - mod_hello.c, hello.pl :)
Michael Dearman [EMAIL PROTECTED] wrote: I've come close to figuring this one out buy following some of the questions I've seen here. But... H1Hello $ENV{REMOTE_HOST}/H1 The remote host doesn't show. Printing out the %ENV, it tain't there. But where does Perl get it. From CGI.pm (which is installed) or where? %ENV is the environment. CGI uses the environment to pass values from the web server to the CGI program. If your script was running under CGI, the web server would put REMOTE_HOST, and other things, in the environment, before forking to run your script. But you're not using CGI, you're using mod_perl. The server isn't setting CGI environment variables and forking to run your script. Your script is being run by a code module that is part of the web server. You need to use Apache specific calls to get the information you need from the web server. mod_perl makes this easy to do using the "Apache request object": $request = Apache-request; $connection = $request-connection; $remote_ip = $connection-remote_ip; Read more about the request object in the mod_perl documentation, to find out how to ask it for the other kinds of information a CGI script normally gets out of the environment. Remember, mod_perl is not CGI (although with Apache::Registry it can look quite similar to CGI) -- Cos (Ofer Inbar) -- [EMAIL PROTECTED] [EMAIL PROTECTED] -- Exodus Professional Services -- [EMAIL PROTECTED] "This may seem a bit weird, but that's okay, because it is weird." -- Larry Wall in perlref(1) man page, Perl 5.001
Re: Eagle Book - mod_hello.c, hello.pl :)
Ofer Inbar wrote: Michael Dearman [EMAIL PROTECTED] wrote: I've come close to figuring this one out buy following some of the questions I've seen here. But... H1Hello $ENV{REMOTE_HOST}/H1 -schnip- normally gets out of the environment. Remember, mod_perl is not CGI (although with Apache::Registry it can look quite similar to CGI) -- Cos (Ofer Inbar) -- [EMAIL PROTECTED] [EMAIL PROTECTED] Thanks Ofer, And along with the guides advice that the use of ENV is clunky anyway, I'll proceed with using the objects. It's just disconcerting when you can't get and example from a book to work. Just didn't know if it was something I didn't have set up right. But now methinks it might be the example was leading me astray. Sure wish the book site had those file listings and any corrections. *hint-hint* Thanks again, Michael Dearman