You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Ryan Thompson <ry...@sasknow.com> on 2002/05/29 05:48:14 UTC

Invoke PHP scripts?

Hi there,

Apologies if this has been asked 2^32 times, but I couldn't seem to
find anything in the archives or on the web which would solve my
problem.

I'm developing a large-ish web site in which I would like to use a
combination of mod_perl (90%) and PHP (10%). I have run into a
roadblock trying to include the output of a PHP script from a mod_perl
script.

This would do fine:

  my $r = Apache->request();
  return $r->lookup_uri($url)->run;

But (and I am familiar with why this happens) run() dumps the results
to STDOUT, so the final HTML does not come through in the correct
order.

I tried to use Apache::SSI in this manner:

  my $r = Apache->request();
  my $ssi = Apache::SSI->new($contents, $r);
  return $ssi->get_output();

(Where $contents is the raw PHP source), but, possibly because of some
Content-type mixup, the output is returned as expected (i.e., not
dumped to stdout), but the PHP source is not interpreted.

So, in short, I need another way to invoke a PHP script from my
mod_perl application... exactly what <!--#include virtual="..." -->
would do.

Help..? :-)

- Ryan

-- 
  Ryan Thompson <ry...@sasknow.com>

  SaskNow Technologies - http://www.sasknow.com
  901 1st Avenue North - Saskatoon, SK - S7K 1Y4

        Tel: 306-664-3600   Fax: 306-664-3630   Saskatoon
  Toll-Free: 877-727-5669     (877-SASKNOW)     North America


Re: Invoke PHP scripts?

Posted by Stas Bekman <st...@stason.org>.
Ryan Thompson wrote:
> Thomas Klausner wrote to modperl@apache.org:
> 
> 
>>Hi!
>>
>>On Tue, May 28, 2002 at 09:48:14PM -0600, Ryan Thompson wrote:
>>
>>
>>>I'm developing a large-ish web site in which I would like to use a
>>>combination of mod_perl (90%) and PHP (10%). I have run into a
>>>roadblock trying to include the output of a PHP script from a
>>>mod_perl script.

How about using notes()?
http://perl.apache.org/release/docs/1.0/guide/snippets.html#Passing_Notes_Between_mod_perl_and_other__non_Perl__Apache_Modules


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Invoke PHP scripts?

Posted by Ryan Thompson <ry...@sasknow.com>.
Thomas Klausner wrote to modperl@apache.org:

> Hi!
>
> On Tue, May 28, 2002 at 09:48:14PM -0600, Ryan Thompson wrote:
>
> > I'm developing a large-ish web site in which I would like to use a
> > combination of mod_perl (90%) and PHP (10%). I have run into a
> > roadblock trying to include the output of a PHP script from a
> > mod_perl script.
>
> As far as I know this is rather impossible with mod_perl 1.x

Hi Thomas,

I was beginning to get that impression myself ;-)

As an unelegant, inefficient, but somewhat useful hack, I ended up
reversing the logic and wrapping my mod_perl script in PHP, with PHP's
virtual() function. It's not altogether efficient, and adds another
layer of complexity, but it works for me, and it's fast/stable enough
to be production code.

> [...]
>
> Apache 2.0 (and mod_perl 2.0) (both in BETA) can do what you want
> unsing Filters.

That'll be great when the technology is ready for production.

- Ryan

-- 
  Ryan Thompson <ry...@sasknow.com>

  SaskNow Technologies - http://www.sasknow.com
  901 1st Avenue North - Saskatoon, SK - S7K 1Y4

        Tel: 306-664-3600   Fax: 306-664-3630   Saskatoon
  Toll-Free: 877-727-5669     (877-SASKNOW)     North America


Re: Invoke PHP scripts?

Posted by Andrew McNaughton <an...@scoop.co.nz>.

On Wed, 29 May 2002, Thomas Klausner wrote:

> Hi!
>
> On Tue, May 28, 2002 at 09:48:14PM -0600, Ryan Thompson wrote:
> > I'm developing a large-ish web site in which I would like to use a
> > combination of mod_perl (90%) and PHP (10%). I have run into a
> > roadblock trying to include the output of a PHP script from a mod_perl
> > script.
> As far as I know this is rather impossible with mod_perl 1.x
>
> You can chain different perl handlers (but only perl handlers) using
> Apache::Filter, or you could let your mod_perl application issue a real http
> request (using LWP), parse the output, and then do what you want with it.

It's possible to lock up your server under heavy load if it's calling
itself via HTTP.  between that and mysql handles I prefer to have separate
apache engines for php and modperl.

Andrew


Re: Invoke PHP scripts?

Posted by Thomas Klausner <do...@zsi.at>.
Hi!

On Tue, May 28, 2002 at 09:48:14PM -0600, Ryan Thompson wrote:
> I'm developing a large-ish web site in which I would like to use a
> combination of mod_perl (90%) and PHP (10%). I have run into a
> roadblock trying to include the output of a PHP script from a mod_perl
> script.
As far as I know this is rather impossible with mod_perl 1.x

You can chain different perl handlers (but only perl handlers) using
Apache::Filter, or you could let your mod_perl application issue a real http
request (using LWP), parse the output, and then do what you want with it.

Apache 2.0 (and mod_perl 2.0) (both in BETA) can do what you want unsing
Filters.



-- 
 D_OMM      +---->  http://domm.zsi.at <-----+
 O_xyderkes |       neu:  Arbeitsplatz       |   
 M_echanen  | http://domm.zsi.at/d/d162.html |
 M_asteuei  +--------------------------------+



RE: Invoke PHP scripts?

Posted by Gabriel C Millerd <gm...@qualhost.com>.
On Wed, 29 May 2002, Jim Helm wrote:

> How about using php in cgi mode and using `php scriptname` from within
> perl to capture the output?  Not the best performance-wise, but it would
> do what you want, I think.
>

	will the cgi environment be preserved?

---
Gabriel Millerd |       When I grow up I want a job where I run around in
Plumber         |    circles chasing my tail like an idiot ten hours a day.
                |                        -- Monster.com


RE: Invoke PHP scripts?

Posted by Jim Helm <jj...@att.net>.
How about using php in cgi mode and using `php scriptname` from within
perl to capture the output?  Not the best performance-wise, but it would
do what you want, I think.

Jim

--
James Helm - Solaris System Administrator   jim.helm@attws.com
WNS National Operations - Core Services     jim.helm-sun@attws.com
AT&T Wireless Services Inc.                 (425) 288-4395 (Desk) 
3555 Monte Villa Pkwy, Bothell, WA  98021   (206) 618-0438 (Cell)  

> -----Original Message-----
> From: Ryan Thompson [mailto:ryan@sasknow.com] 
> Sent: Tuesday, May 28, 2002 8:48 PM
> To: modperl@apache.org
> Subject: Invoke PHP scripts?
> 
> 
> 
> Hi there,
> 
> Apologies if this has been asked 2^32 times, but I couldn't 
> seem to find anything in the archives or on the web which 
> would solve my problem.
> 
> I'm developing a large-ish web site in which I would like to 
> use a combination of mod_perl (90%) and PHP (10%). I have run 
> into a roadblock trying to include the output of a PHP script 
> from a mod_perl script.
> 
> This would do fine:
> 
>   my $r = Apache->request();
>   return $r->lookup_uri($url)->run;
> 
> But (and I am familiar with why this happens) run() dumps the 
> results to STDOUT, so the final HTML does not come through in 
> the correct order.
> 
> I tried to use Apache::SSI in this manner:
> 
>   my $r = Apache->request();
>   my $ssi = Apache::SSI->new($contents, $r);
>   return $ssi->get_output();
> 
> (Where $contents is the raw PHP source), but, possibly 
> because of some Content-type mixup, the output is returned as 
> expected (i.e., not dumped to stdout), but the PHP source is 
> not interpreted.
> 
> So, in short, I need another way to invoke a PHP script from 
> my mod_perl application... exactly what <!--#include 
> virtual="..." --> would do.
> 
> Help..? :-)
> 
> - Ryan
> 
> -- 
>   Ryan Thompson <ry...@sasknow.com>
> 
>   SaskNow Technologies - http://www.sasknow.com
>   901 1st Avenue North - Saskatoon, SK - S7K 1Y4
> 
>         Tel: 306-664-3600   Fax: 306-664-3630   Saskatoon
>   Toll-Free: 877-727-5669     (877-SASKNOW)     North America
>