Re: problem calling a file under mod_perl2

2007-05-29 Thread Alicia Amadoz
Hi,

I have found that somehow 'startup.pl' isn't loaded or it can't be read.
It has rw-r--r-- permissions. Have I the correct configuration for
mod_perl2?

I would be very grateful if anyone could help me with this.
Regards.

Here is my httpd.conf:

LoadModule perl_module modules/mod_perl.so

#Alias /perl-cgi/ "/usr/local/apache2/htdocs/www/p_scripts/perl-cgi/"

#
#AllowOverride None
#Options None
#Order allow,deny
#Allow from all
#

PerlSwitches -wT
PerlPostConfigRequire
/usr/local/apache2/htdocs/www/p_scripts/perl-cgi/startup.pl
PerlSwitches -I/usr/local/apache2/htdocs/www/p_scripts/perl-cgi/

SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
Order allow,deny
Allow from all


And my startup.pl:

#!/usr/bin/perl -w

use strict;

# to use other libraries in other @INC path  
# use lib qw(/absolute/path/);
use lib qw(/usr/local/apache2/htdocs/www/p_scripts/perl-cgi/);
  
# preload all mp2 modules
# use ModPerl::MethodLookup;
# ModPerl::MethodLookup::preload_all_modules();

use ModPerl::Util (); #for CORE::GLOBAL::exit

use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::RequestUtil ();

use Apache2::ServerRec ();
use Apache2::ServerUtil ();
use Apache2::Connection ();
use Apache2::Log ();

use APR::Table ();

# use ModPerl::Registry ();

use Apache2::Const -compile => ':common';
use APR::Const -compile => ':common';

1;



Re: problem calling a file under mod_perl2

2007-05-29 Thread Perrin Harkins

On 5/29/07, Alicia Amadoz <[EMAIL PROTECTED]> wrote:

I have found that somehow 'startup.pl' isn't loaded or it can't be read.
It has rw-r--r-- permissions. Have I the correct configuration for
mod_perl2?


That should be fine, but there might be an enclosing directory with
bad permissions.  The simplest way to check is to su to the user who
you run apache as and try to read the file.

How do you know it isn't being loaded?

- Perrin


Re: problem calling a file under mod_perl2

2007-05-29 Thread Alicia Amadoz

> 
> How do you know it isn't being loaded?
> 
> - Perrin
> 
> 

In startup.pl there are some modules called and they were also called
from my script file. So, I deleted the use syntax from my script file so
that the modules only were called from startup.pl. If I have an error
like 'Can't locate object method via package', I guess that startup.pl
isn't being loaded.

Thanks for your help.



Re: problem calling a file under mod_perl2

2007-05-29 Thread Perrin Harkins

On 5/29/07, Alicia Amadoz <[EMAIL PROTECTED]> wrote:

In startup.pl there are some modules called and they were also called
from my script file. So, I deleted the use syntax from my script file so
that the modules only were called from startup.pl. If I have an error
like 'Can't locate object method via package', I guess that startup.pl
isn't being loaded.


That sounds like it should work.  You can also try using a warn()
statement in startup.pl.  It should show up on the terminal when you
run apachectl if your startup.pl is being called.

- Perrin


Re: problem calling a file under mod_perl2

2007-05-29 Thread Alicia Amadoz
Hi,

How I should write a warn() statement in startup.pl? I am new to Perl
and I wrote 'warn;' and 'warn(use lib 'path');' but the errors where
like 'Warning: something's wrong'.

Another thing that I am thinking it could be related to my problem is
that I am using php on my website and I call the perl script with
system(). It works ok if I write my subroutines in the same perl script
file that it's called from php file or if I write the absolute path to
perl_functions.pl in require (in my perl script). Could this be related
with loading startup.pl? I am new to mod_perl and I am wondering if I
call a perl file from a php file with system() it isn't being run under
mod_perl but under a system shell. In my system() statement I don't
invoke perl interpreter, just the location of the perl script that is
configured in httpd.conf to be executed under mod_perl:

system('search.pl');

Well, I would appreciate any idea or help as usual.
Regards.

> On 5/29/07, Alicia Amadoz <[EMAIL PROTECTED]> wrote:
> > In startup.pl there are some modules called and they were also called
> > from my script file. So, I deleted the use syntax from my script file so
> > that the modules only were called from startup.pl. If I have an error
> > like 'Can't locate object method via package', I guess that startup.pl
> > isn't being loaded.
> 
> That sounds like it should work.  You can also try using a warn()
> statement in startup.pl.  It should show up on the terminal when you
> run apachectl if your startup.pl is being called.
> 
> - Perrin
> 
> 



Re: problem calling a file under mod_perl2

2007-05-29 Thread Clinton Gormley
On Tue, 2007-05-29 at 16:32 +0200, Alicia Amadoz wrote:
> Hi,
> 
> How I should write a warn() statement in startup.pl? I am new to Perl
> and I wrote 'warn;' and 'warn(use lib 'path');' but the errors where
> like 'Warning: something's wrong'.

That means that it is being loaded - the "something's wrong" just means
that there was nothing passed to the warn statement.

if you said : warn('LOADED') it would print the LOADED message.
> 
> Another thing that I am thinking it could be related to my problem is
> that I am using php on my website and I call the perl script with
> system().


There's your problem - you aren't using mod_perl at all - the system
call launches a new perl interpreter, compiles the code, runs it and
exits.

not very efficient - same as using ordinary CGI.




Re: problem calling a file under mod_perl2

2007-05-29 Thread Alicia Amadoz
> 
> There's your problem - you aren't using mod_perl at all - the system
> call launches a new perl interpreter, compiles the code, runs it and
> exits.
> 
> not very efficient - same as using ordinary CGI.
> 

Ok, then I finally understand what is happening. But is there any other
option to use every script under mod_perl even calling it from php?

Thanks for your help.
Regards.



Re: problem calling a file under mod_perl2

2007-05-29 Thread Clinton Gormley
> > 
> 
> Ok, then I finally understand what is happening. But is there any other
> option to use every script under mod_perl even calling it from php?

The only way I can think of would be to make a web request in PHP, so
the PHP program does an HTTP request to your web server, to call the
perl script, then does something with the data that is returned.

Not optimal, but it may suit your needs
> 
> Thanks for your help.
> Regards.
> 



Re: few newbie quesitons..

2007-05-29 Thread Jay Buffington

I'm a little behind here, but this thread caught my eye:

On 5/6/07, Perrin Harkins <[EMAIL PROTECTED]> wrote:

On 5/6/07, James. L <[EMAIL PROTECTED]> wrote:
> my question is
> once the app produce the html, does the memory
> allocated by the parsed data get released to perl?
> that memory will be reused by other mod_perl app?

No, Perl doesn't work that way.  It will keep that memory allocated
for that variable unless you undef the variable explicitly.


It's my understanding that even if you explicitly undef a variable,
perl doesn't release the memory.

Here's a demonstration:

[EMAIL PROTECTED]:~$ cat memusage.pl
#!/usr/bin/perl

use GTop ();

print "Base line:\n";
print_mem();

my %squared;
foreach my $num ( 1..500_000 ) {
   $squared{ $num } = $num**2;
}

print "\nAfter using some memory:\n";
print_mem();

%squared = undef;

print "\nAfter undef'ing variable:\n";
print_mem();

sub print_mem {
   my $proc_mem = GTop->new()->proc_mem($$);
   print "size: " . $proc_mem->size() . "\n";
   print "vsize:" . $proc_mem->vsize() . "\n";
   print "resident: " . $proc_mem->resident() . "\n";
   print "share:" . $proc_mem->share() . "\n";
   print "rss:  " . $proc_mem->rss() . "\n";
}


[EMAIL PROTECTED]:~$ perl memusage.pl
Base line:
size: 7180288
vsize:7180288
resident: 2936832
share:1916928
rss:  2932736

After using some memory:
size: 58142720
vsize:58142720
resident: 49774592
share:1941504
rss:  49774592

After undef'ing variable:
size: 58142720
vsize:58142720
resident: 49774592
share:1941504
rss:  49774592


Re: few newbie quesitons..

2007-05-29 Thread Perrin Harkins

On 5/29/07, Jay Buffington <[EMAIL PROTECTED]> wrote:

On 5/6/07, Perrin Harkins <[EMAIL PROTECTED]> wrote:
> On 5/6/07, James. L <[EMAIL PROTECTED]> wrote:
> > my question is
> > once the app produce the html, does the memory
> > allocated by the parsed data get released to perl?
> > that memory will be reused by other mod_perl app?
>
> No, Perl doesn't work that way.  It will keep that memory allocated
> for that variable unless you undef the variable explicitly.

It's my understanding that even if you explicitly undef a variable,
perl doesn't release the memory.


He was asking about it being released back to perl for use within the
same process, not about releasing it back to the operating system for
use in other processes.

- Perrin


Re: problem calling a file under mod_perl2

2007-05-29 Thread Malcolm J Harwood
On Tuesday 29 May 2007, Clinton Gormley wrote:

> > Ok, then I finally understand what is happening. But is there any other
> > option to use every script under mod_perl even calling it from php?
>
> The only way I can think of would be to make a web request in PHP, so
> the PHP program does an HTTP request to your web server, to call the
> perl script, then does something with the data that is returned.
>
> Not optimal, but it may suit your needs

I actually do the reverse for one situation (call php from mod_perl by making 
a request and processing the result). 

As long as you have the capacity to handle the double request, it works fine, 
and is almost certainly more efficient than spawning a new perl process every 
time.


-- 
Suppose they held a war and nobody came?