This mod_perl handler fetches a parm from the URL, and passes it into the notes table for a subrequest. Then, it executes that subrequest, which is the following PHP file:package TW::Apache::Play; use strict; use warnings; use Apache::Request; use Apache::Constants qw( :common ); sub handler { my $r = Apache::Request->new( shift ); my $username = $r->param('username') || "alester"; $r->send_http_header( "text/html" ); print "<html><body>"; print "<h3>Looking up \"$username\" via PHP</h3>"; my $sub = $r->lookup_uri( "/foo.php" ); $sub->notes->set( username => $username ); my $rc = $sub->run(); my $notes = $sub->notes; print "custid=$notes->{custid}<BR>"; print "contact=$notes->{contact}<BR>"; print "All done!"; print "</body></html>"; return OK; } 1;
The PHP gets the username note from Apache, does a lookup in the database, and then passes back two columns in the notes table. Control is the passed back to the mod_perl handler, which extracts those two columns from the notes table and displays them on the screen.<?php $username = apache_note( "username" ); $cols = sqldo( "select custid,contact from users where username=:u +", Array( ":u"=>$username ) ); apache_note( "custid", $cols["CUSTID"] ); apache_note( "contact", $cols["CONTACT"] ); ?>
Of course, in real life, the PHP code will be calls to some hairy business logic that is thoroughly debugged that I don't want to rewrite on the Perl side.
Is there any danger in doing this? As I understand the notes table, they're per-request only, and won't stick around after the request is completed, so I don't have to worry about children polluting each other. Surely there's a performance hit of some kind, but I assume it's only relatively small.
Any words of experience from anyone out there?
xoxo,
Andy
In reply to Talking to PHP from Perl by petdance
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |