You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Rob Saunders <ro...@saunders.yourideal.co.uk> on 2004/02/19 14:55:13 UTC

[Question] Newbie: Apache::SubProcess to spawn PHP commands

Hi,

I'm using Mason to dynamically create templated web-pages and this is 
all working okay, adding headers/footers/menus etc... via the 
autohandler and "$m->call_next" for the content.

However, I also have a number of inherited PHP scripts, the output of 
which I'd also like to format using my Mason components. Now, when I 
access those .php scripts, I get a download dialog pop-up stating that 
we have an unrecognised mime type etc... Ok. That's because the php is 
"application/x-httpd-php" rather than "text/html". (The PHP is processed 
  okay if I add an appropriate FilesMatch/SetHandler directive for those 
.php files, but obviously doesn't do the Mason formatting stuff)

So, I've created a module "Apache::PHP" which uses the 
Apache::SubProcess module to exec the command "php -f $r->filename". 
This Apache::PHP is then chained to the Mason Handler, the idea being 
that I could parse the file using Apache::PHP, output the html to Mason 
which then does the wizzy formatting stuff and ta-da!. Sounds feasible I 
thought, but when parsing the PHP in the child process, I get a 
Segmentation fault... yeuch!. My guess is that somewhere within Apache 
there's a limit to the amount of memory a request can grab, and, in 
spawning php, this limit is exceeded. So, does anyone have any ideas how 
I can either work around this, i.e. alternatives to spawn system 
commands from a request, or increase the amount of memory that a request 
can use... All links, suggestions welcome.

System info:
RH9 linux running 2.6.2 kernel on i686 with glibc 2.3.2-11.9
Apache 1.3.29
mod_perl 1.29
perl 5.8.3
php 4.3.4
Mason 1.25

Thanks in advance.

Rob

________________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com
________________________________________________________________________

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [Question] Newbie: Apache::SubProcess to spawn PHP commands

Posted by Stas Bekman <st...@stason.org>.
Rob Saunders wrote:
> Hi,
> 
> I'm using Mason to dynamically create templated web-pages and this is 
> all working okay, adding headers/footers/menus etc... via the 
> autohandler and "$m->call_next" for the content.
> 
> However, I also have a number of inherited PHP scripts, the output of 
> which I'd also like to format using my Mason components. Now, when I 
> access those .php scripts, I get a download dialog pop-up stating that 
> we have an unrecognised mime type etc... Ok. That's because the php is 
> "application/x-httpd-php" rather than "text/html". (The PHP is processed 
>  okay if I add an appropriate FilesMatch/SetHandler directive for those 
> .php files, but obviously doesn't do the Mason formatting stuff)
> 
> So, I've created a module "Apache::PHP" which uses the 
> Apache::SubProcess module to exec the command "php -f $r->filename". 
> This Apache::PHP is then chained to the Mason Handler, the idea being 
> that I could parse the file using Apache::PHP, output the html to Mason 
> which then does the wizzy formatting stuff and ta-da!. Sounds feasible I 
> thought, but when parsing the PHP in the child process, I get a 
> Segmentation fault... yeuch!. My guess is that somewhere within Apache 
> there's a limit to the amount of memory a request can grab, and, in 
> spawning php, this limit is exceeded. So, does anyone have any ideas how 
> I can either work around this, i.e. alternatives to spawn system 
> commands from a request, or increase the amount of memory that a request 
> can use... All links, suggestions welcome.

That sounds feasible, but not practical, as you bring the performance down to 
nada by calling a bunch of external processes. You are much better off looking 
at Apache2/mod_perl2 where you can use filters to parse the output of various 
handlers. I'm not sure though, how easy it is to convert Mason to act as a 
filter. For information on filters, see:
http://perl.apache.org/docs/2.0/user/handlers/filters.html

In mod_perl 1, you could try using Apache::Filter 
http://search.cpan.org/dist/Apache-Filter/
but it's probably going to be much slower and more memory consuming because of 
the buffering.

-- 
__________________________________________________________________
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

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html