Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Perl, PHP mod_perl

by jai_dgl (Beadle)
on Oct 28, 2009 at 10:39 UTC ( [id://803641]=perlquestion: print w/replies, xml ) Need Help??

jai_dgl has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
1. I have a Perl script which is written in a fashion to run only in command line.( not in browser )
Ex: perl script.pl -s "some option" -t "some more option"
2. There is a PHP script which has to call the Perl Script, using system call ( using Exec ) and then the same PHP script collects the console output and makes some cosmetic work and displays in browser.

3. Now the problem is the system call takes a huge resource and my client is suggesting me to include mod_perl.
is it possible to include my Perl script in mod_perl with the same architecture or I need to convert the Perl script in such way that could run in Browser.
Thanks Jey

Replies are listed 'Best First'.
Re: Perl, PHP mod_perl
by Errto (Vicar) on Oct 28, 2009 at 15:19 UTC
    Well, it won't be exactly the same architecture obviuosly. But it can be similar. You'll have to install and configure mod_perl. The feature you'll want to use is ModPerl::Registry which allows you to run your Perl program as if it were a CGI program. You'll need to make a few changes in the script itself:
    • Have some other logic for passing the command line options. If they should be dynamic, use a query string or something. If they should be static, have them come from config variables in your Apache config
    • You'll have to generate the proper response headers for "CGI" output. Now you're presumably doing it in the PHP script, so you have to do that in Perl instead.
    • Likewise with whatever cosmetic changes you're doing.
Re: Perl, PHP mod_perl
by Your Mother (Archbishop) on Oct 28, 2009 at 16:34 UTC

    Some ideas (speculation without knowing what your Perl is doing)-

    • Rewrite the Perl code in PHP and use it directly; they can translate pretty directly sometimes.
    • Turn the Perl script into a daemon listening on a socket or a URI and have the PHP make the requests there. This is essentially the same solution as mod_perl but *might* be easier depending on the situation and your Perl chops. Search CPAN or here for "daemon" for modules and recommendations.
    • mod_perl. Errto's registry suggestion is probably the easiest way to do this.
    • Turn your script into fastcgi (FCGI). It is generally easier and more likely to be available/supported than mod_perl. They are roughly equivalent in terms of performance. mod_perl is much deeper but its apache hooks are rarely needed in plain web scripting.

    Whatever you pick, you're in for a bit of work/learning. I'd personally go with the fastcgi solution. Good luck.

Re: Perl, PHP mod_perl
by saberworks (Curate) on Oct 28, 2009 at 16:30 UTC
    First you should determine whether mod_perl will actually help. mod_perl is helpful when you've got a LOT of requests coming in for a resource, and each of those requests result in a process being spawned, and this process start/stop cycle can take up a lot of resources. If this is the case, mod_perl can help (you're having resource issues because you have too many requests coming in).

    However, if your perl script is taking up resources because it's doing something resource-intensive, likely mod_perl won't help. For example, if it's only accessed occasionally and if it's taking an hour to run and pegging the cpu/disk/memory/whatever because it's processing a huge file, mod_perl won't help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://803641]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-18 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found