You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Justin Luster <ju...@sawtoothsoftware.com> on 2002/10/03 01:41:10 UTC

Graphics and mod_perl

 

I'm new to mod_perl and I'm really enjoying it.  It has really improved
performance.  Right now I'm just using Modperl::Registry to speed up
things.  I have a question about showing graphics using a Perl Script
and running it through mod_perl.  

 

Using Perl under regular CGI to create a dynamic web page I have always
used:

 

print "<img src=\"thefile.jpg\">";

 

and this would display the graphic to the web page assuming that the
file "thefile.jpg"  was in the same directory as the Perl script .  If
the graphic was in another directory then something like:

 

print "<img src=\"../graphics/thefile.jpg\">";

 

was used.  Now that I'm using mod_perl and an Alias to my cgi-bin I'm
having difficulties knowing how to reference the graphics file.  The
following directive is in my httpd.conf file.

 

Alias /ssiweb/ "C:/Server/htdocs/develop/cgi-bin/"

<Location /ssiweb>

  SetHandler perl-script

  PerlResponseHandler ModPerl::Registry

  Options +ExecCGI

  PerlOptions +ParseHeaders

</Location>

 

It seems that the current working directory for the Perl scripts when
run under mod_perl is in the bin directory where Apache.exe is.  I have
considered using absolute paths but even that does not seem to work
correctly with graphics.  I could also do something like:

 

print "<img src=\"http://www.mysite.com/graphics/thefile.jpg\">";

 

but it seems that there is a delay in displaying the graphic when I do
this.

 

Where is the current working directory when running a Perl script under
mod_perl.  

 

I would appreciate any help.

 

Thanks.

 


Re: Graphics and mod_perl

Posted by Per Einar Ellefsen <pe...@oslo.online.no>.
At 01:41 03.10.2002, Justin Luster wrote:

>
>
>I m new to mod_perl and I m really enjoying it.  It has really improved 
>performance.  Right now I m just using Modperl::Registry to speed up 
>things.  I have a question about showing graphics using a Perl Script and 
>running it through mod_perl.
>
>
>
>Using Perl under regular CGI to create a dynamic web page I have always used:
>
>
>
>print <img src=\ thefile.jpg\ > ;
>
>
>
>and this would display the graphic to the web page assuming that the file 
>thefile.jpg  was in the same directory as the Perl script .  If the 
>graphic was in another directory then something like:
>
>
>
>print <img src=\ ../graphics/thefile.jpg\ > ;
>
>[...]
>
>print <img src=\ http://www.mysite.com/graphics/thefile.jpg\ > ;
>
>but it seems that there is a delay in displaying the graphic when I do this.
>
>Where is the current working directory when running a Perl script under 
>mod_perl.

Hello Justin,

You seem to misunderstand the working of the HTML <img> tag. All you're 
doing is to give an idea to the *browser* about where it should find the 
image, relatively to the *URI* of your script.
Simply put, before you had:
/cgi-bin/yourscript.cgi ---> img src="thefile.jpg" ---> browser tries to 
fetch /cgi-bin/thefile.jpg
Now, you have:
/ssiweb/yourscript.pl ----> img src="../graphics/thefile.jpg" ---> browser 
fetches /ssiweb/../graphics/thefile.jpg = /graphics/thefile.jpg

You have almost found the best solution when in doubt: using absolute URIs.
However, as you noticed, using the full URL is slower because the browser 
has to check the DNS again etc etc.
So, if your graphics are acccessible as 
http://www.example.com/graphics/file.jpg, then you can insert an img tag 
with src="/graphics/file.jpg". Note the first slash which says to the 
browser "Begin at the root of this site and fetch the following URI".

Ok?


-- 
Per Einar Ellefsen
pereinar@oslo.online.no



Re: Graphics and mod_perl

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Wed, 2 Oct 2002, Justin Luster wrote:

> I'm new to mod_perl and I'm really enjoying it.  It has really improved
> performance.  Right now I'm just using Modperl::Registry to speed up
> things.  I have a question about showing graphics using a Perl Script
> and running it through mod_perl.  
[ ... ] 
> It seems that the current working directory for the Perl scripts when
> run under mod_perl is in the bin directory where Apache.exe is.  

That behaviour was introduced into Win32 Apache some time back,
one reason being, as I understand it, is so that one could
double-click on the Apache icon to start it up.

>  I have considered using absolute paths but even that does not
> seem to work correctly with graphics.
[ ... ] 
As Per Einar mentioned in an earlier reply, using absolute server
paths is the best solution - generally, for cgi and registry
scripts, one should not rely on an assumption of a current
working directory. There is a module, FindBin, which reveals the
directory of a script, but as explained in the perl-5.8 docs for
FindBin, there's some caveats to using it under mod_perl and
other persistant Perl environments.

-- 
best regards,
randy kobes