Programming :  Student Freelance Forum For Work Experience Builders' (CertificationPoint) The fastest message board... ever.
 
PERL-Passing Notes Between mod_perl and other (non-Perl) Apache Modules
Posted by: adcertpoint (Moderator)
Date: April 29, 2020 04:38PM

The notes() method can be used to make various Apache modules talk to each other. In the following snippet the PHP module talks to the mod_perl code (PHP code):
if (isset($user) && substr($user,0,1) == "+"winking smiley {
apache_note("user", substr($user,1));
virtual("/internal/getquota"winking smiley;
$quota = apache_note("quota"winking smiley;
$usage_pp = apache_note("usage_pp"winking smiley;
$percent_pp = apache_note("percent_pp"winking smiley;
if ($quota)
$message .= " | Using $percent_pp% of $quota_pp limit";
}

The PHP code sets the user and the username pair using the notes mechanism. Then issuing a sub-request to a perl handler:
use Apache::Constants qw(REDIRECT OK);
my $r = shift;
my $notes = $r->main->notes();
my ($quota,usage_pp,percent_pp) = getquota($notes->{user}||'');
$r->notes('quota',$quota);
$r->notes('usage_pp',$usage_pp);
$r->notes('percent_pp',$percent_pp);
return OK;

which retrieves the username from the notes (using $r->main->notes), uses some getquota() function to get the quota related data and then sets the acquired data in the notes for the PHP code. Now the PHP code reads the data from the notes and proceeds with setting $message if $quota is set.

So any Apache modules can communicate with each other over the Apache notes() mechanism.

You can use notes along with the sub-request methods lookup_uri() and lookup_filename() too. To make it work, you need to set a note in the sub-request. For example if you want to call a php sub-request from within mod_perl and pass it a note, you can do it in the following way:
my $subr = $r->lookup_uri('wizard.php3');
$subr->notes('answer' => 42);
$subr->run;

As of the time of this writing you cannot access the parent request tables from a PHP handler, therefore you must set this note for the sub-request. Whereas if the sub-request is running in the mod_perl domain, you can always keep the notes in the parent request notes table and access them via the method main():
$r->main->notes('answer');

Options: ReplyQuote


Sorry, only registered users may post in this forum.
This forum powered by Phorum.