perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tony Clayton <>
Subject Re: mod_perl2 and PHP
Date Sat, 06 Aug 2005 17:07:56 GMT
Quoting Thomas Klausner <>:

> Hi!
> Is it possible and advisable to write the complex part of an
> application
> (the Controller, if you like) in mod_perl2 and use PHP as a frontend
> (or
> View) ?

It should be possible, perhaps by calling php from apache subrequests
the mod_perl code, but it won't be efficient, and doesn't sound very
As an alternative, you might be able to use SOAP/RPC requests in the
code to offload the backend work to a mod_perl SOAP/RPC server.  Again,
not very efficient or practical.

> While I personally prefere Template::Toolkit as a presentation
> language, the
> project I'm currently getting involved in has quite a lot of
> PHP-people and
> not that many (read: me) Perl people.

> So what I thought is: use Perl to implement the rather complex
> business
> logic, and PHP for rendering (and getting form input to the
> 'backend').

If they are keen to learn new stuff (perl) provided the learning curve
isn't too steep, then using HTML::Mason or embperl instead of TT might
be an easier sell as the concept and syntax is similar to php.  I've
never used TT (and I'm certainly not knocking it), but from what I've
seen it's a whole 'nother language (albeit small) to learn.  You'll
want to do some research on these before recommending them for a
project, of course.
> But: can I create a datastructure in Perl (in an ResponseHandler) and
> pass
> it on to PHP running also as an ResponseHandler, but afterwards.
> Would I
> need to stuff data in ENV? Can I pass complex data structures around?
> Do I
> have to serialise (to yaml/xml) between Perl and PHP?

In a previous project that involved both perl and php components, I was
successful in sharing nested data structures between the languages,
essentially by telling perl how to import structures from php include
files.  In my case, we had legacy php pages that we were replacing with
HTML::Mason components, but needed to share data structures (menu items
and such) in the meantime.

Here's a quick synopsis.  Create a file 'data.dat' like:
$data = array(
        "Node 1" => array(
             array("Node 1.1" => "foo"),
             array("Node 1.2" => "bar"),
        "Node 2" => array(
             array("Node 2.1" => "baz"),

Now, from a php script, do:

And from a perl script, do:
sub array {return [@_] }
my $data;
open FILE, "<data.dat";
my $script;
{local $/; $script = <FILE>; }
close FILE;
$script =~ s/^(?:<\?php|\?>)//msg;
eval $script;

You should be able to do nested data structures without a problem.  You
can't marshall objects or references using this method.  If simple,
nested structures will suit your needs, it should be easy enough to
create a data marshalling class in perl to create PHP structures from
perl structures.

EDIT:  As an afterthought, I checked CPAN to see if there were modules
that did something similar, and found PHP::Include and

> Or is this a bad idea altogether and I should use a different
> approach (Like
> forcing everyone to read the Badger)?

If you are in a position of influence with a potential opportunity to
introduce mod_perl to PHP developers, then do the world a favour and
take that challenge.  :)


View raw message