Trouble with script execution

2014-05-18 Thread Worik Stanton
I am having a nproblem executing my handler.

The short of it is it is when I make a change to the script I have to
restart the server to get it noticed, and it does not always call the
same code.

The lng of it:

I have a package with a 'handler' function.

It starts...

package Apache::Script;
use strict;
use Apache2::Const qw(:common);
use Apache2::Connection;
[snip]
sub handler {
warn Apache::Script::handler $$ '.join(, , @_).';
my $r = shift;
[snip]
Many more lines like...
warn Apache::Script::handler;

And in the config file:
Location /Script
SetHandler  perl-script
PerlResponseHandler Apache::Script
/Location


Repeatedly loading the URL I get different results almost every time.
With the first 'warn' statement producing oyutput almst every iteration
and occasionally the later warn statements not being executed, and often
with no output.

Making changes t the script (adding debugging 'warn' statements) are
only reliably (ish) noticed if I restart the server.  There is some
unreliability in my code (bugs) I am trying to track down but it is
confounded by the fact I am not sure what mod_perl is doing.

There seems to be a time element.  After restarting the server
everything goes well for a while  (minutes) but soon behaviour changes
and I am back to only some of the code executing (with no oither changes
but the passing of time).

I thought mod_perl would reload code that changed.  Is this wrong?

Worik
-- 
The only true evil is turning people into things
 Granny Weatherwax
   worik.stan...@gmail.com 021-1680650, (03) 4821804
  Aotearoa (New Zealand)



signature.asc
Description: OpenPGP digital signature


Re: Trouble with script execution

2014-05-18 Thread John Dunlap
No, you have to restart the server for code changes to be noticed.
On May 18, 2014 6:48 PM, Worik Stanton worik.stan...@gmail.com wrote:

 I am having a nproblem executing my handler.

 The short of it is it is when I make a change to the script I have to
 restart the server to get it noticed, and it does not always call the
 same code.

 The lng of it:

 I have a package with a 'handler' function.

 It starts...

 package Apache::Script;
 use strict;
 use Apache2::Const qw(:common);
 use Apache2::Connection;
 [snip]
 sub handler {
 warn Apache::Script::handler $$ '.join(, , @_).';
 my $r = shift;
 [snip]
 Many more lines like...
 warn Apache::Script::handler;

 And in the config file:
 Location /Script
 SetHandler  perl-script
 PerlResponseHandler Apache::Script
 /Location


 Repeatedly loading the URL I get different results almost every time.
 With the first 'warn' statement producing oyutput almst every iteration
 and occasionally the later warn statements not being executed, and often
 with no output.

 Making changes t the script (adding debugging 'warn' statements) are
 only reliably (ish) noticed if I restart the server.  There is some
 unreliability in my code (bugs) I am trying to track down but it is
 confounded by the fact I am not sure what mod_perl is doing.

 There seems to be a time element.  After restarting the server
 everything goes well for a while  (minutes) but soon behaviour changes
 and I am back to only some of the code executing (with no oither changes
 but the passing of time).

 I thought mod_perl would reload code that changed.  Is this wrong?

 Worik
 --
 The only true evil is turning people into things
  Granny Weatherwax
worik.stan...@gmail.com 021-1680650, (03) 4821804
   Aotearoa (New Zealand)




What about debugging?

2014-05-18 Thread Worik Stanton
Is there a way to get useful debugging info?

I am getting messages like:

 failed to resolve handler `Apache::AdMachine::MyHandler;'

Which says something is wrong, but offers no clue.

If I have a bug like:

my $z = ; # Clearly wrong

I get a useful error message.

So when I see:

 failed to resolve handler `Apache::AdMachine::MyHandler;'

I am a bit lost

Worik
-- 
The only true evil is turning people into things
 Granny Weatherwax
   worik.stan...@gmail.com 021-1680650, (03) 4821804
  Aotearoa (New Zealand)



signature.asc
Description: OpenPGP digital signature


Re: Trouble with script execution

2014-05-18 Thread Worik Stanton
On 19/05/14 11:34, John Dunlap wrote:
 No, you have to restart the server for code changes to be noticed.

Does that mean I have to restart my server for every change to a script?

Worik

-- 
The only true evil is turning people into things
 Granny Weatherwax
   worik.stan...@gmail.com 021-1680650, (03) 4821804
  Aotearoa (New Zealand)



signature.asc
Description: OpenPGP digital signature


Re: What about debugging?

2014-05-18 Thread Worik Stanton
On 19/05/14 12:03, Worik Stanton wrote:
 Is there a way to get useful debugging info?
 
 I am getting messages like:
 
  failed to resolve handler `Apache::AdMachine::MyHandler;'
 

Excuse my sillieness.

 `Apache::AdMachine::MyHandler;' had a ';' on the end.  The error
message was very sensible, and I was unobservant,

Sorry to waste your time.

Worik
-- 
The only true evil is turning people into things
 Granny Weatherwax
   worik.stan...@gmail.com 021-1680650, (03) 4821804
  Aotearoa (New Zealand)



signature.asc
Description: OpenPGP digital signature


Re: Trouble with script execution

2014-05-18 Thread Brad Van Sickle

Yep you need to restart to see your changes.

Believe it or not, that's one of the *nice* things about mod_perl. 
Instead of compiling the code during each execution  as PERL does when 
executed as a purely interpreted language , mod_perl causes each Apache 
child process to compile the code during it's first request/execution 
and then caches that compiled version of that code.  You will need to 
restart the web server to clear that cache and force your changes to 
take effect.


This is probably why you're getting inconsistent results after code 
changes, your seeing some requests that are handled by new child 
processes that are compiling the latest version of your code and some 
requests that are being handled by old child processes which are still 
serving previous versions that they've complied and cached.


It may seem inconvenient for you, but this type of caching is a 
*necessity* when running PERL on any sort of real website that gets an 
appreciable amount of traffic for performance reasons.


There are methods you can employ that tell Apache to automatically 
reload when it sees code change, pretty easy to find if you dig around 
the Internet.Although I wouldn't use this in a production system.




On 5/18/2014 8:04 PM, Worik Stanton wrote:

On 19/05/14 11:34, John Dunlap wrote:

No, you have to restart the server for code changes to be noticed.

Does that mean I have to restart my server for every change to a script?

Worik





Re: API Docs

2014-05-18 Thread Jie Gao
* André Warnier a...@ice-sa.com wrote:

 Date: Sat, 17 May 2014 11:59:24 +0200
 From: André Warnier a...@ice-sa.com
 To: mod_perl list modperl@perl.apache.org
 Subject: Re: API Docs
 User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
 
 Worik Stanton wrote:
 On 16/05/14 21:09, André Warnier wrote:
 Maybe you should start here :
 https://perl.apache.org/docs/2.0/user/handlers/intro.html#What_are_Handlers_
 
 
 Thank you.  That is very useful
 
 Welcome.
 One thing which you cannot complain about apparently, is the number
 of answers you're getting.  mod_perl advocacy seems alive and well.
 Don't hesitate to ask if you have further questions.
...
 
I think it was because list mail was being held up somewhere, and people
thought nobody had replied.

It was interesting to see the variety of responses to the question. :-)

I have certainly learnt something from them. 

Regards,



Jie


Re: Trouble with script execution

2014-05-18 Thread Worik Stanton
On 19/05/14 12:13, Brad Van Sickle wrote:
 Yep you need to restart to see your changes.

I am sure I read somewhere that mod_perl monitors scripts and reloads
them if the modification date changes.  But oh well.  It definitely
notices sometimes.

cheers
Worik

-- 
The only true evil is turning people into things
 Granny Weatherwax
   worik.stan...@gmail.com 021-1680650, (03) 4821804
  Aotearoa (New Zealand)



signature.asc
Description: OpenPGP digital signature


Re: Trouble with script execution

2014-05-18 Thread John Dunlap
That hasn't been my experience. I always need to restart the server. One of
the challenges with that is that objects can persist in memory between
requests because the perl runtime persists between requests. If the
script changes, how do you apply those changes to objects instances which
already exist in memory? It is not a simple problem and it exists in other
languages(java) as well. Entire companies(ZeroTurnaround) have been built
around solving this kind of problem. The only reason that you can make
changes in a language like php without a server restart is because php
objects cannot persist between requests like they can in perl or Java and
that approach has its own disadvantages.
On May 18, 2014 9:47 PM, Worik Stanton worik.stan...@gmail.com wrote:

 On 19/05/14 12:13, Brad Van Sickle wrote:
  Yep you need to restart to see your changes.

 I am sure I read somewhere that mod_perl monitors scripts and reloads
 them if the modification date changes.  But oh well.  It definitely
 notices sometimes.

 cheers
 Worik

 --
 The only true evil is turning people into things
  Granny Weatherwax
worik.stan...@gmail.com 021-1680650, (03) 4821804
   Aotearoa (New Zealand)